[llvm] [InstCombine] Simplify compare abs(X) and X. (PR #76385)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 2 03:45:43 PST 2024
================
@@ -7109,6 +7109,56 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
}
}
+ // 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))) ||
+ (match(Op0, m_Value(X)) &&
+ match(Op1,
+ m_Intrinsic<Intrinsic::abs>(m_Specific(X), m_Constant(C))))) {
----------------
nikic wrote:
You are matching the operands in swapped order here, but keep the old predicate. This will result in a miscompile (as your last test shows).
https://github.com/llvm/llvm-project/pull/76385
More information about the llvm-commits
mailing list