[llvm] 495ed8d - [SLP]Fix PR70507: freeze poisonous insts to avoid poison propagation.

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 2 10:41:22 PDT 2023


Author: Alexey Bataev
Date: 2023-11-02T10:37:38-07:00
New Revision: 495ed8d8c8b3795dd51595aad7a192189f2cfeab

URL: https://github.com/llvm/llvm-project/commit/495ed8d8c8b3795dd51595aad7a192189f2cfeab
DIFF: https://github.com/llvm/llvm-project/commit/495ed8d8c8b3795dd51595aad7a192189f2cfeab.diff

LOG: [SLP]Fix PR70507: freeze poisonous insts to avoid poison propagation.

If the reduction instruction is not bool logical op, but reduced within bool logical op reduction list, need to freeze to avoid poison propagation.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
    llvm/test/Transforms/SLPVectorizer/X86/bool-logical-op-reduction-with-poison.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 14d2bcfd53f6353..66608d09139bac0 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14616,15 +14616,15 @@ class HorizontalReduction {
                                                    Instruction *RedOp1,
                                                    Instruction *RedOp2,
                                                    bool InitStep) {
-        if (!isBoolLogicOp(RedOp1))
+        if (!AnyBoolLogicOp)
           return;
-        if ((!InitStep && LHS == VectorizedTree) ||
-            getRdxOperand(RedOp1, 0) == LHS || isGuaranteedNotToBePoison(LHS))
+        if (isBoolLogicOp(RedOp1) &&
+            ((!InitStep && LHS == VectorizedTree) ||
+             getRdxOperand(RedOp1, 0) == LHS || isGuaranteedNotToBePoison(LHS)))
           return;
-        if (!isBoolLogicOp(RedOp2))
-          return;
-        if ((!InitStep && RHS == VectorizedTree) ||
-            getRdxOperand(RedOp2, 0) == RHS || isGuaranteedNotToBePoison(RHS)) {
+        if (isBoolLogicOp(RedOp2) && ((!InitStep && RHS == VectorizedTree) ||
+                                      getRdxOperand(RedOp2, 0) == RHS ||
+                                      isGuaranteedNotToBePoison(RHS))) {
           std::swap(LHS, RHS);
           return;
         }

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/bool-logical-op-reduction-with-poison.ll b/llvm/test/Transforms/SLPVectorizer/X86/bool-logical-op-reduction-with-poison.ll
index e0a90e2fb4993a9..408ea6239972893 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/bool-logical-op-reduction-with-poison.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/bool-logical-op-reduction-with-poison.ll
@@ -15,7 +15,8 @@ define i1 @test(i32 %0, i32 %1, i32 %p) {
 ; CHECK-NEXT:    [[TMP7:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP6]])
 ; CHECK-NEXT:    [[OP_RDX:%.*]] = select i1 [[TMP7]], i1 true, i1 [[CMP6]]
 ; CHECK-NEXT:    [[OP_RDX1:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP1]]
-; CHECK-NEXT:    [[OP_RDX2:%.*]] = select i1 [[OP_RDX]], i1 true, i1 [[OP_RDX1]]
+; CHECK-NEXT:    [[TMP8:%.*]] = freeze i1 [[OP_RDX]]
+; CHECK-NEXT:    [[OP_RDX2:%.*]] = select i1 [[TMP8]], i1 true, i1 [[OP_RDX1]]
 ; CHECK-NEXT:    ret i1 [[OP_RDX2]]
 ;
 entry:


        


More information about the llvm-commits mailing list