aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@hotmail.com>2025-02-01 08:48:32 +0100
committerGitHub <noreply@github.com>2025-02-01 08:48:32 +0100
commit9399a1ddb82ff400f237a2353d17871106e9005c (patch)
treebc4b5d73e3fc3e61409a7723ef1bcc76da86aff6 /llvm/lib/Analysis/InstructionSimplify.cpp
parent2d17fc4ca31dcc8fdc5df0c554d548e348a5ee0b (diff)
downloadllvm-9399a1ddb82ff400f237a2353d17871106e9005c.zip
llvm-9399a1ddb82ff400f237a2353d17871106e9005c.tar.gz
llvm-9399a1ddb82ff400f237a2353d17871106e9005c.tar.bz2
[InstSimplify] Handle trunc to i1 in Select with bit test folds. (#122944)
Proof: https://alive2.llvm.org/ce/z/Jncqb2
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index f76bfa9..21c9375 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4612,12 +4612,11 @@ static Value *simplifyCmpSelOfMaxMin(Value *CmpLHS, Value *CmpRHS,
return nullptr;
}
-/// An alternative way to test if a bit is set or not uses sgt/slt instead of
-/// eq/ne.
-static Value *simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *CmpRHS,
- CmpPredicate Pred, Value *TrueVal,
- Value *FalseVal) {
- if (auto Res = decomposeBitTestICmp(CmpLHS, CmpRHS, Pred))
+/// An alternative way to test if a bit is set or not.
+/// uses e.g. sgt/slt or trunc instead of eq/ne.
+static Value *simplifySelectWithBitTest(Value *CondVal, Value *TrueVal,
+ Value *FalseVal) {
+ if (auto Res = decomposeBitTest(CondVal))
return simplifySelectBitTest(TrueVal, FalseVal, Res->X, &Res->Mask,
Res->Pred == ICmpInst::ICMP_EQ);
@@ -4728,11 +4727,6 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
return FalseVal;
}
- // Check for other compares that behave like bit test.
- if (Value *V =
- simplifySelectWithFakeICmpEq(CmpLHS, CmpRHS, Pred, TrueVal, FalseVal))
- return V;
-
// 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.
@@ -4984,6 +4978,9 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
simplifySelectWithICmpCond(Cond, TrueVal, FalseVal, Q, MaxRecurse))
return V;
+ if (Value *V = simplifySelectWithBitTest(Cond, TrueVal, FalseVal))
+ return V;
+
if (Value *V = simplifySelectWithFCmp(Cond, TrueVal, FalseVal, Q, MaxRecurse))
return V;