diff options
author | Alexey Bataev <a.bataev@outlook.com> | 2023-11-02 09:29:25 -0700 |
---|---|---|
committer | Alexey Bataev <a.bataev@outlook.com> | 2023-11-02 10:37:38 -0700 |
commit | 495ed8d8c8b3795dd51595aad7a192189f2cfeab (patch) | |
tree | acf4589ef76eb50953626d7f5b16d1693f6094dd | |
parent | d483abd0fdd032c4169f8fcaedd2bc63986f7a40 (diff) | |
download | llvm-495ed8d8c8b3795dd51595aad7a192189f2cfeab.zip llvm-495ed8d8c8b3795dd51595aad7a192189f2cfeab.tar.gz llvm-495ed8d8c8b3795dd51595aad7a192189f2cfeab.tar.bz2 |
[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.
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 14 | ||||
-rw-r--r-- | llvm/test/Transforms/SLPVectorizer/X86/bool-logical-op-reduction-with-poison.ll | 3 |
2 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 14d2bcf..66608d0 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14616,15 +14616,15 @@ public: 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 e0a90e2..408ea62 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: |