[llvm] [InstSimplify] `A == MIN_INT ? B != MIN_INT : A < B` to `A < B` (PR #120177)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 02:53:09 PST 2024
================
@@ -4608,6 +4608,45 @@ static Value *simplifySelectWithEquivalence(Value *CmpLHS, Value *CmpRHS,
return nullptr;
}
+/// `A == MIN_INT ? B != MIN_INT : A < B` --> `A < B`
+/// `A == MAX_INT ? B != MAX_INT : A > B` --> `A > B`
+static Value *foldSelectWithExtremeEqCond(Value *CmpLHS, Value *CmpRHS,
+ Value *TrueVal, Value *FalseVal) {
+ CmpPredicate Pred;
+ Value *A, *B;
+
+ if (!match(FalseVal, m_ICmp(Pred, m_Value(A), m_Value(B))))
+ return nullptr;
+
+ // make sure `CmpLHS` is on the LHS of `FalseVal`.
+ if (match(CmpLHS, m_Specific(B))) {
----------------
nikic wrote:
```suggestion
if (CmpLHS == B) {
```
etc
https://github.com/llvm/llvm-project/pull/120177
More information about the llvm-commits
mailing list