Otherwise instcombine gets stuck in a cycle. The canonicalization was
added in D55961.
This patch fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12400
Differential D56679
[InstCombine] Don't undo 0 - (X * Y) canonicalization when combining subs. fhahn on Jan 14 2019, 11:31 AM. Authored by
Details
Otherwise instcombine gets stuck in a cycle. The canonicalization was This patch fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12400
Diff Detail Event TimelineComment Actions We are sure that we want to break the cycle here, and not at the other end?
Comment Actions I think it's fine to break the cycle here, but we should address the problem pattern directly - we want to avoid the transform on a constant expression rather than a plain constant. So something like this (the variable named "CI" is misleading since that usually refers to "ConstantInt"): Index: lib/Transforms/InstCombine/InstCombineAddSub.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAddSub.cpp (revision 351077) +++ lib/Transforms/InstCombine/InstCombineAddSub.cpp (working copy) @@ -1649,7 +1649,6 @@ // X - A*-B -> X + A*B // X - -A*B -> X + A*B Value *A, *B; - Constant *CI; if (match(Op1, m_c_Mul(m_Value(A), m_Neg(m_Value(B))))) return BinaryOperator::CreateAdd(Op0, Builder.CreateMul(A, B)); @@ -1656,8 +1655,8 @@ // X - A*CI -> X + A*-CI // No need to handle commuted multiply because multiply handling will // ensure constant will be move to the right hand side. - if (match(Op1, m_Mul(m_Value(A), m_Constant(CI)))) { - Value *NewMul = Builder.CreateMul(A, ConstantExpr::getNeg(CI)); + if (match(Op1, m_Mul(m_Value(A), m_Constant(C))) && !isa<ConstantExpr>(C)) { + Value *NewMul = Builder.CreateMul(A, ConstantExpr::getNeg(C)); return BinaryOperator::CreateAdd(Op0, NewMul); } } We needed a similar fix here:
Comment Actions LGTM
|
Please change the 'CI' to 'C' in this comment to match the updated code.