[llvm] 889215a - [SLP]Followup fix for the poisonous logical op in reductions
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 26 05:22:57 PST 2024
Author: Alexey Bataev
Date: 2024-12-26T05:11:26-08:00
New Revision: 889215a30ed60474e573f9632d1fa362dfa1b04e
URL: https://github.com/llvm/llvm-project/commit/889215a30ed60474e573f9632d1fa362dfa1b04e
DIFF: https://github.com/llvm/llvm-project/commit/889215a30ed60474e573f9632d1fa362dfa1b04e.diff
LOG: [SLP]Followup fix for the poisonous logical op in reductions
If the VectorizedTree still may generate poisonous value, but it is not
the original operand of the reduction op, need to check if Res still the
operand, to generate correct code.
Fixes #114905
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll
llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 57f3016fbe1e06..e9fc89fa242a7a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -19821,21 +19821,21 @@ class HorizontalReduction {
Builder.SetCurrentDebugLocation(
cast<Instruction>(ReductionOps.front().front())->getDebugLoc());
if (AnyBoolLogicOp) {
-
- if (auto It = ReducedValsToOps.find(VectorizedTree);
- It == ReducedValsToOps.end() ||
+ auto It = ReducedValsToOps.find(VectorizedTree);
+ auto It1 = ReducedValsToOps.find(Res);
+ if ((It == ReducedValsToOps.end() && It1 == ReducedValsToOps.end()) ||
isGuaranteedNotToBePoison(VectorizedTree, AC) ||
- any_of(It->getSecond(), [&](Instruction *I) {
- return isBoolLogicOp(I) &&
- getRdxOperand(I, 0) == VectorizedTree;
- })) {
+ (It != ReducedValsToOps.end() &&
+ any_of(It->getSecond(), [&](Instruction *I) {
+ return isBoolLogicOp(I) &&
+ getRdxOperand(I, 0) == VectorizedTree;
+ }))) {
;
- } else if (auto It = ReducedValsToOps.find(Res);
- It == ReducedValsToOps.end() ||
- isGuaranteedNotToBePoison(Res, AC) ||
- any_of(It->getSecond(), [&](Instruction *I) {
+ } else if (isGuaranteedNotToBePoison(Res, AC) ||
+ (It1 != ReducedValsToOps.end() &&
+ any_of(It1->getSecond(), [&](Instruction *I) {
return isBoolLogicOp(I) && getRdxOperand(I, 0) == Res;
- })) {
+ }))) {
std::swap(VectorizedTree, Res);
} else {
VectorizedTree = Builder.CreateFreeze(VectorizedTree);
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll b/llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll
index 0771fabef3e028..e0b3ff714162fb 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll
@@ -428,7 +428,7 @@ define i1 @logical_and_icmp_extra_op(<4 x i32> %x, <4 x i32> %y, i1 %c) {
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <4 x i32> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = freeze <4 x i1> [[TMP1]]
; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> [[TMP2]])
-; CHECK-NEXT: [[OP_RDX:%.*]] = select i1 [[TMP3]], i1 [[C:%.*]], i1 false
+; CHECK-NEXT: [[OP_RDX:%.*]] = select i1 [[C:%.*]], i1 [[TMP3]], i1 false
; CHECK-NEXT: ret i1 [[OP_RDX]]
;
%x0 = extractelement <4 x i32> %x, i32 0
@@ -456,7 +456,7 @@ define i1 @logical_or_icmp_extra_op(<4 x i32> %x, <4 x i32> %y, i1 %c) {
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <4 x i32> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = freeze <4 x i1> [[TMP1]]
; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP2]])
-; CHECK-NEXT: [[OP_RDX:%.*]] = select i1 [[TMP3]], i1 true, i1 [[C:%.*]]
+; CHECK-NEXT: [[OP_RDX:%.*]] = select i1 [[C:%.*]], i1 true, i1 [[TMP3]]
; CHECK-NEXT: ret i1 [[OP_RDX]]
;
%x0 = extractelement <4 x i32> %x, i32 0
diff --git a/llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll b/llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll
index 101f66f3313045..f0cfd99a892a13 100644
--- a/llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll
+++ b/llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll
@@ -14,7 +14,7 @@ define i1 @test(<4 x i32> %x) {
; CHECK-NEXT: [[C3:%.*]] = icmp slt i32 [[X3]], 0
; CHECK-NEXT: [[TMP2:%.*]] = freeze i1 [[C3]]
; CHECK-NEXT: [[OP_RDX:%.*]] = select i1 [[TMP2]], i1 [[C1]], i1 false
-; CHECK-NEXT: [[OP_RDX1:%.*]] = select i1 [[OP_RDX]], i1 [[TMP1]], i1 false
+; CHECK-NEXT: [[OP_RDX1:%.*]] = select i1 [[TMP1]], i1 [[OP_RDX]], i1 false
; CHECK-NEXT: ret i1 [[OP_RDX1]]
;
%x0 = extractelement <4 x i32> %x, i32 0
More information about the llvm-commits
mailing list