[llvm] [InstCombine] Simplify compare abs(X) and X. (PR #76385)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 03:14:47 PST 2024
================
@@ -6860,6 +6860,54 @@ Instruction *InstCombinerImpl::foldICmpCommutative(ICmpInst::Predicate Pred,
return foldICmpAddOpConst(X, *C, Pred);
}
+ // abs(X) >= X --> true
+ // abs(X) u<= X --> true
+ // abs(X) < X --> false
+ // abs(X) u> X --> false
+ // abs(X) u>= X --> IsIntMinPosion ? `X > -1`: `X u<= INTMIN`
+ // abs(X) <= X --> IsIntMinPosion ? `X > -1`: `X u<= INTMIN`
+ // abs(X) == X --> IsIntMinPosion ? `X > -1`: `X u<= INTMIN`
+ // abs(X) u< X --> IsIntMinPosion ? `X < 0` : `X > INTMIN`
+ // abs(X) > X --> IsIntMinPosion ? `X < 0` : `X > INTMIN`
+ // abs(X) != X --> IsIntMinPosion ? `X < 0` : `X > INTMIN`
+ {
+ Value *X;
+ Constant *C;
+ if ((match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X), m_Constant(C))) &&
+ match(Op1, m_Specific(X)))) {
----------------
dtcxzyw wrote:
```suggestion
if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X), m_Constant(C))) &&
match(Op1, m_Specific(X))) {
```
https://github.com/llvm/llvm-project/pull/76385
More information about the llvm-commits
mailing list