diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-02-24 16:57:45 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-02-24 16:57:45 +0000 |
commit | 9907d3c8b4accff34f451f5737fec81d21a12098 (patch) | |
tree | 576d4b7fcedfc8b1aa3efe88541f2cb2ef7c7042 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | 986a024c191e58c586aa5f3e22adfb9ef174b31e (diff) | |
download | bcm5719-llvm-9907d3c8b4accff34f451f5737fec81d21a12098.tar.gz bcm5719-llvm-9907d3c8b4accff34f451f5737fec81d21a12098.zip |
[InstCombine] canonicalize add/sub with bool
add A, sext(B) --> sub A, zext(B)
We have to choose 1 of these forms, so I'm opting for the
zext because that's easier for value tracking.
The backend should be prepared for this change after:
D57401
rL353433
This is also a preliminary step towards reducing the amount
of bit hackery that we do in IR to optimize icmp/select.
That should be waiting to happen at a later optimization stage.
The seeming regression in the fuzzer test was discussed in:
D58359
We were only managing that fold in instcombine by luck, and
other passes should be able to deal with that better anyway.
llvm-svn: 354748
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index bf92b5dc559..e2d4774b71f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1118,6 +1118,12 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { return BinaryOperator::CreateSub(RHS, A); } + // Canonicalize sext to zext for better value tracking potential. + // add A, sext(B) --> sub A, zext(B) + if (match(&I, m_c_Add(m_Value(A), m_OneUse(m_SExt(m_Value(B))))) && + B->getType()->isIntOrIntVectorTy(1)) + return BinaryOperator::CreateSub(A, Builder.CreateZExt(B, Ty)); + // A + -B --> A - B if (match(RHS, m_Neg(m_Value(B)))) return BinaryOperator::CreateSub(LHS, B); |