[llvm] [InstSimplify] Move Select with bittest folds. (PR #122944)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 10:30:32 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Andreas Jonson (andjo403)
<details>
<summary>Changes</summary>
Preparation to handle `trunc to i1` in this fold.
results in no changes in local run of llvm-opt-benchmark
---
Full diff: https://github.com/llvm/llvm-project/pull/122944.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+13-13)
``````````diff
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index d69747e30f884d..05dedd219c2667 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4612,14 +4612,16 @@ 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))
- return simplifySelectBitTest(TrueVal, FalseVal, Res->X, &Res->Mask,
- Res->Pred == ICmpInst::ICMP_EQ);
+/// An alternative way to test if a bit is set or not uses e.g. sgt/slt instead
+/// of eq/ne.
+static Value *simplifySelectWithBitTest(Value *CondVal, Value *TrueVal,
+ Value *FalseVal) {
+
+ if (auto *ICmp = dyn_cast<ICmpInst>(CondVal))
+ if (auto Res = decomposeBitTestICmp(
+ ICmp->getOperand(0), ICmp->getOperand(1), ICmp->getPredicate()))
+ return simplifySelectBitTest(TrueVal, FalseVal, Res->X, &Res->Mask,
+ Res->Pred == ICmpInst::ICMP_EQ);
return nullptr;
}
@@ -4728,11 +4730,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 +4981,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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/122944
More information about the llvm-commits
mailing list