Skip to content

Commit 47769d3

Browse files
rotaterightvchuravy
authored andcommitted
[VectorCombine] fix insertion point of shuffles
As shown in issue llvm#60649, the new shuffles were being inserted before a phi, and that is invalid. It seems like most test coverage for this fold (foldSelectShuffle) lives in the AArch64 dir, but this doesn't repro there for a base target. (cherry picked from commit e42aaf1)
1 parent c2b24cd commit 47769d3

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1660,16 +1660,16 @@ bool VectorCombine::foldSelectShuffle(Instruction &I, bool FromReduction) {
16601660
return SSV->getOperand(Op);
16611661
return SV->getOperand(Op);
16621662
};
1663-
Builder.SetInsertPoint(SVI0A->getNextNode());
1663+
Builder.SetInsertPoint(SVI0A->getInsertionPointAfterDef());
16641664
Value *NSV0A = Builder.CreateShuffleVector(GetShuffleOperand(SVI0A, 0),
16651665
GetShuffleOperand(SVI0A, 1), V1A);
1666-
Builder.SetInsertPoint(SVI0B->getNextNode());
1666+
Builder.SetInsertPoint(SVI0B->getInsertionPointAfterDef());
16671667
Value *NSV0B = Builder.CreateShuffleVector(GetShuffleOperand(SVI0B, 0),
16681668
GetShuffleOperand(SVI0B, 1), V1B);
1669-
Builder.SetInsertPoint(SVI1A->getNextNode());
1669+
Builder.SetInsertPoint(SVI1A->getInsertionPointAfterDef());
16701670
Value *NSV1A = Builder.CreateShuffleVector(GetShuffleOperand(SVI1A, 0),
16711671
GetShuffleOperand(SVI1A, 1), V2A);
1672-
Builder.SetInsertPoint(SVI1B->getNextNode());
1672+
Builder.SetInsertPoint(SVI1B->getInsertionPointAfterDef());
16731673
Value *NSV1B = Builder.CreateShuffleVector(GetShuffleOperand(SVI1B, 0),
16741674
GetShuffleOperand(SVI1B, 1), V2B);
16751675
Builder.SetInsertPoint(Op0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=vector-combine -S -mtriple=x86_64-- | FileCheck %s
3+
4+
target datalayout = "e-p:64:64-i64:64-f80:128-n8:16:32:64-S128"
5+
6+
; This would insert before a phi instruction which is invalid IR.
7+
8+
define <4 x double> @PR60649() {
9+
; CHECK-LABEL: @PR60649(
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: br label [[END:%.*]]
12+
; CHECK: unreachable:
13+
; CHECK-NEXT: br label [[END]]
14+
; CHECK: end:
15+
; CHECK-NEXT: [[T0:%.*]] = phi <4 x double> [ zeroinitializer, [[ENTRY:%.*]] ], [ zeroinitializer, [[UNREACHABLE:%.*]] ]
16+
; CHECK-NEXT: [[T1:%.*]] = phi <4 x double> [ zeroinitializer, [[ENTRY]] ], [ zeroinitializer, [[UNREACHABLE]] ]
17+
; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <4 x double> [[T0]], <4 x double> [[T0]], <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
18+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x double> [[T0]], <4 x double> [[T0]], <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
19+
; CHECK-NEXT: [[TMP2:%.*]] = fdiv <4 x double> [[TMP1]], <double 0.000000e+00, double 0.000000e+00, double undef, double undef>
20+
; CHECK-NEXT: [[TMP3:%.*]] = fmul <4 x double> [[TMP0]], <double 0.000000e+00, double 0.000000e+00, double undef, double undef>
21+
; CHECK-NEXT: [[T5:%.*]] = shufflevector <4 x double> [[TMP2]], <4 x double> [[TMP3]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
22+
; CHECK-NEXT: ret <4 x double> [[T5]]
23+
;
24+
entry:
25+
br label %end
26+
27+
unreachable:
28+
br label %end
29+
30+
end:
31+
%t0 = phi <4 x double> [ zeroinitializer, %entry ], [ zeroinitializer, %unreachable ]
32+
%t1 = phi <4 x double> [ zeroinitializer, %entry ], [ zeroinitializer, %unreachable ]
33+
%t2 = shufflevector <4 x double> zeroinitializer, <4 x double> zeroinitializer, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
34+
%t3 = fdiv <4 x double> %t0, %t2
35+
%t4 = fmul <4 x double> %t0, %t2
36+
%t5 = shufflevector <4 x double> %t3, <4 x double> %t4, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
37+
ret <4 x double> %t5
38+
}

0 commit comments

Comments
 (0)