summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-02-18 22:20:09 +0000
committerSanjay Patel <spatel@rotateright.com>2017-02-18 22:20:09 +0000
commit53c5c3d65df3d48fd147b7786ef56cf9da6548d2 (patch)
tree0289773ebb088597a27473e757ed1db508c56821 /llvm/lib/Transforms
parentfe67255961e25c1d88888831d5badb3ec96b4ba2 (diff)
downloadbcm5719-llvm-53c5c3d65df3d48fd147b7786ef56cf9da6548d2.tar.gz
bcm5719-llvm-53c5c3d65df3d48fd147b7786ef56cf9da6548d2.zip
[InstCombine] add nsw/nuw X, signbit --> or X, signbit
Changing to 'or' (rather than 'xor' when no wrapping flags are set) allows icmp simplifies to happen as expected. Differential Revision: https://reviews.llvm.org/D29729 llvm-svn: 295574
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 998ef492fc1..95f266a3d5f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1044,9 +1044,16 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
const APInt *Val;
if (match(RHS, m_APInt(Val))) {
- // X + (signbit) --> X ^ signbit
- if (Val->isSignBit())
+ if (Val->isSignBit()) {
+ // If wrapping is not allowed, then the addition must set the sign bit:
+ // X + (signbit) --> X | signbit
+ if (I.hasNoSignedWrap() || I.hasNoUnsignedWrap())
+ return BinaryOperator::CreateOr(LHS, RHS);
+
+ // If wrapping is allowed, then the addition flips the sign bit of LHS:
+ // X + (signbit) --> X ^ signbit
return BinaryOperator::CreateXor(LHS, RHS);
+ }
// Is this add the last step in a convoluted sext?
Value *X;
OpenPOWER on IntegriCloud