[llvm] [InstCombine] Fold abs(a * abs(b)) --> abs(a * b) (PR #78110)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 16:16:59 PST 2024
================
@@ -218,6 +218,17 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
: BinaryOperator::CreateNeg(Op0);
}
+ {
+ // abs(a * abs(b)) --> abs(a * b)
+ Value *A, *B;
+ if (match(&I, m_OneUse(m_c_Mul(m_Value(A),
+ m_Intrinsic<Intrinsic::abs>(m_Value(B)))))) {
+ Value *New =
+ HasNSW ? Builder.CreateNSWMul(A, B) : Builder.CreateMul(A, B);
----------------
dtcxzyw wrote:
The nsw flag preserving is incorrect.
Alive2: https://alive2.llvm.org/ce/z/kXQA3p
https://github.com/llvm/llvm-project/pull/78110
More information about the llvm-commits
mailing list