Skip to content

Commit 8993367

Browse files
committed
[SLP]Be more pessimistic about poisonous reductions
Consider all possible reductions ops as being non-poisoning boolean logical operations, which require freeze to be fully correct. https://alive2.llvm.org/ce/z/TKWDMP Fixes llvm#114738
1 parent 2588b8b commit 8993367

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -19490,9 +19490,7 @@ class HorizontalReduction {
1949019490
// To prevent poison from leaking across what used to be sequential,
1949119491
// safe, scalar boolean logic operations, the reduction operand must be
1949219492
// frozen.
19493-
if ((isBoolLogicOp(RdxRootInst) ||
19494-
(AnyBoolLogicOp && VL.size() != TrackedVals.size())) &&
19495-
!isGuaranteedNotToBePoison(VectorizedRoot))
19493+
if (AnyBoolLogicOp && !isGuaranteedNotToBePoison(VectorizedRoot))
1949619494
VectorizedRoot = Builder.CreateFreeze(VectorizedRoot);
1949719495

1949819496
// Emit code to correctly handle reused reduced values, if required.

llvm/test/Transforms/SLPVectorizer/reudction-or-non-poisoned.ll

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ define i1 @test(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {
99
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x i32> [[TMP2]], i32 [[C]], i32 2
1010
; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x i32> [[TMP3]], i32 [[X]], i32 3
1111
; CHECK-NEXT: [[TMP5:%.*]] = icmp sgt <4 x i32> [[TMP4]], <i32 1, i32 1, i32 1, i32 1>
12-
; CHECK-NEXT: [[TMP6:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP5]])
12+
; CHECK-NEXT: [[TMP7:%.*]] = freeze <4 x i1> [[TMP5]]
13+
; CHECK-NEXT: [[TMP6:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP7]])
1314
; CHECK-NEXT: ret i1 [[TMP6]]
1415
;
1516
%cmp = icmp sgt i32 %x, 1

0 commit comments

Comments
 (0)