Skip to content

Commit 2d06375

Browse files
committed
[SLP] add test for miscompile with reduction (PR43948); NFC
1 parent 592dd45 commit 2d06375

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

llvm/test/Transforms/SLPVectorizer/X86/reduction.ll

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,58 @@ for.end: ; preds = %for.cond.for.end_cr
6868
ret i32 %sum.0.lcssa
6969
}
7070

71+
; FIXME: PR43948 - https://bugs.llvm.org/show_bug.cgi?id=43948
72+
; The extra use of a non-vectorized element of a reduction must not be killed.
73+
74+
define i32 @horiz_max_multiple_uses([32 x i32]* %x, i32* %p) {
75+
; CHECK-LABEL: @horiz_max_multiple_uses(
76+
; CHECK-NEXT: [[X0:%.*]] = getelementptr [32 x i32], [32 x i32]* [[X:%.*]], i64 0, i64 0
77+
; CHECK-NEXT: [[X4:%.*]] = getelementptr [32 x i32], [32 x i32]* [[X]], i64 0, i64 4
78+
; CHECK-NEXT: [[X5:%.*]] = getelementptr [32 x i32], [32 x i32]* [[X]], i64 0, i64 5
79+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[X0]] to <4 x i32>*
80+
; CHECK-NEXT: [[TMP2:%.*]] = load <4 x i32>, <4 x i32>* [[TMP1]], align 4
81+
; CHECK-NEXT: [[T4:%.*]] = load i32, i32* [[X4]]
82+
; CHECK-NEXT: [[T5:%.*]] = load i32, i32* [[X5]]
83+
; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
84+
; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = icmp sgt <4 x i32> [[TMP2]], [[RDX_SHUF]]
85+
; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select <4 x i1> [[RDX_MINMAX_CMP]], <4 x i32> [[TMP2]], <4 x i32> [[RDX_SHUF]]
86+
; CHECK-NEXT: [[RDX_SHUF1:%.*]] = shufflevector <4 x i32> [[RDX_MINMAX_SELECT]], <4 x i32> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
87+
; CHECK-NEXT: [[RDX_MINMAX_CMP2:%.*]] = icmp sgt <4 x i32> [[RDX_MINMAX_SELECT]], [[RDX_SHUF1]]
88+
; CHECK-NEXT: [[RDX_MINMAX_SELECT3:%.*]] = select <4 x i1> [[RDX_MINMAX_CMP2]], <4 x i32> [[RDX_MINMAX_SELECT]], <4 x i32> [[RDX_SHUF1]]
89+
; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x i32> [[RDX_MINMAX_SELECT3]], i32 0
90+
; CHECK-NEXT: [[TMP4:%.*]] = icmp sgt i32 [[TMP3]], [[T4]]
91+
; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i32 [[TMP3]], i32 [[T4]]
92+
; CHECK-NEXT: [[C012345:%.*]] = icmp sgt i32 [[TMP5]], [[T5]]
93+
; CHECK-NEXT: [[T17:%.*]] = select i1 [[C012345]], i32 [[TMP5]], i32 [[T5]]
94+
; CHECK-NEXT: [[THREE_OR_FOUR:%.*]] = select i1 undef, i32 3, i32 4
95+
; CHECK-NEXT: store i32 [[THREE_OR_FOUR]], i32* [[P:%.*]], align 8
96+
; CHECK-NEXT: ret i32 [[T17]]
97+
;
98+
%x0 = getelementptr [32 x i32], [32 x i32]* %x, i64 0, i64 0
99+
%x1 = getelementptr [32 x i32], [32 x i32]* %x, i64 0, i64 1
100+
%x2 = getelementptr [32 x i32], [32 x i32]* %x, i64 0, i64 2
101+
%x3 = getelementptr [32 x i32], [32 x i32]* %x, i64 0, i64 3
102+
%x4 = getelementptr [32 x i32], [32 x i32]* %x, i64 0, i64 4
103+
%x5 = getelementptr [32 x i32], [32 x i32]* %x, i64 0, i64 5
104+
105+
%t0 = load i32, i32* %x0
106+
%t1 = load i32, i32* %x1
107+
%t2 = load i32, i32* %x2
108+
%t3 = load i32, i32* %x3
109+
%t4 = load i32, i32* %x4
110+
%t5 = load i32, i32* %x5
111+
112+
%c01 = icmp sgt i32 %t0, %t1
113+
%s5 = select i1 %c01, i32 %t0, i32 %t1
114+
%c012 = icmp sgt i32 %s5, %t2
115+
%t8 = select i1 %c012, i32 %s5, i32 %t2
116+
%c0123 = icmp sgt i32 %t8, %t3
117+
%rdx4 = select i1 %c0123, i32 %t8, i32 %t3
118+
%EXTRA_USE = icmp sgt i32 %rdx4, %t4
119+
%t14 = select i1 %EXTRA_USE, i32 %rdx4, i32 %t4
120+
%c012345 = icmp sgt i32 %t14, %t5
121+
%t17 = select i1 %c012345, i32 %t14, i32 %t5
122+
%THREE_OR_FOUR = select i1 %EXTRA_USE, i32 3, i32 4
123+
store i32 %THREE_OR_FOUR, i32* %p, align 8
124+
ret i32 %t17
125+
}

0 commit comments

Comments
 (0)