diff options
author | Sanjay Patel <spatel@rotateright.com> | 2021-04-05 16:47:29 -0400 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2021-04-05 16:52:34 -0400 |
commit | e2a0f512eacad0699be9660f668726d7deb2cd75 (patch) | |
tree | 4bb90a8ffd0a3837a0ef9903a5874809c28889fd | |
parent | 78e5cf66fec52c8e6e665c3c9e64d38498d94a5d (diff) | |
download | llvm-e2a0f512eacad0699be9660f668726d7deb2cd75.zip llvm-e2a0f512eacad0699be9660f668726d7deb2cd75.tar.gz llvm-e2a0f512eacad0699be9660f668726d7deb2cd75.tar.bz2 |
[InstSimplify] fix potential miscompile in select value equivalence
This is the sibling fix to c590a9880d7a -
as there, we can't subsitute a vector value the equality
compare replacement that we are trying requires that the
comparison is true for the entire value. Vector select
can be partly true/false.
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 8 | ||||
-rw-r--r-- | llvm/test/Transforms/InstSimplify/select.ll | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 23bb5e6..5804f68 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4149,10 +4149,12 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, TrueVal, FalseVal)) return V; - // If we have an equality comparison, then we know the value in one of the - // arms of the select. See if substituting this value into the arm and + // If we have a scalar equality comparison, then we know the value in one of + // the arms of the select. See if substituting this value into the arm and // simplifying the result yields the same value as the other arm. - if (Pred == ICmpInst::ICMP_EQ) { + // Note that the equivalence/replacement opportunity does not hold for vectors + // because each element of a vector select is chosen independently. + if (Pred == ICmpInst::ICMP_EQ && !CondVal->getType()->isVectorTy()) { if (SimplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, Q, /* AllowRefinement */ false, MaxRecurse) == TrueVal || diff --git a/llvm/test/Transforms/InstSimplify/select.ll b/llvm/test/Transforms/InstSimplify/select.ll index 00cb5c1..acb998b 100644 --- a/llvm/test/Transforms/InstSimplify/select.ll +++ b/llvm/test/Transforms/InstSimplify/select.ll @@ -1029,7 +1029,10 @@ declare i32 @llvm.ctpop.i32(i32) define <2 x i32> @vec_select_no_equivalence(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @vec_select_no_equivalence( -; CHECK-NEXT: ret <2 x i32> zeroinitializer +; CHECK-NEXT: [[X10:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> undef, <2 x i32> <i32 1, i32 0> +; CHECK-NEXT: [[COND:%.*]] = icmp eq <2 x i32> [[X]], zeroinitializer +; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[COND]], <2 x i32> [[X10]], <2 x i32> zeroinitializer +; CHECK-NEXT: ret <2 x i32> [[S]] ; %x10 = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> <i32 1, i32 0> %cond = icmp eq <2 x i32> %x, zeroinitializer |