summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-06-07 20:03:45 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-06-07 20:03:45 +0000
commit2683802ba086fd8d0ff981dda17ff096e8be4f25 (patch)
treed571235f5ea6fbaf458fcf96559b44bc2755dd6f /llvm/lib/Analysis/InstructionSimplify.cpp
parent1f67a3cba9b09636c56e2109d8a35ae96dc15782 (diff)
downloadbcm5719-llvm-2683802ba086fd8d0ff981dda17ff096e8be4f25.tar.gz
bcm5719-llvm-2683802ba086fd8d0ff981dda17ff096e8be4f25.zip
[InstSimplify] shl nuw C, %x -> C iff signbit is set on C.
Summary: `%r = shl nuw i8 C, %x` As per langref: ``` If the nuw keyword is present, then the shift produces a poison value if it shifts out any non-zero bits. ``` Thus, if the sign bit is set on `C`, then `%x` can only be `0`, which means that `%r` can only be `C`. Or in other words, set sign bit means that the signed value is negative, so the constant is `<= 0`. https://rise4fun.com/Alive/WMk https://rise4fun.com/Alive/udv Was mentioned in D47428 review. We already handle the `0` constant, https://godbolt.org/g/UZq1sJ, so this only handles negative constants. Could use computeKnownBits() / LazyValueInfo, but the cost-benefit analysis (https://reviews.llvm.org/D47891) suggests it isn't worth it. Reviewers: spatel, craig.topper Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47883 llvm-svn: 334222
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index cdcb81b8060..0b150f86a32 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1226,6 +1226,13 @@ static Value *SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
Value *X;
if (match(Op0, m_Exact(m_Shr(m_Value(X), m_Specific(Op1)))))
return X;
+
+ // shl nuw i8 C, %x -> C iff C has sign bit set.
+ if (isNUW && match(Op0, m_Negative()))
+ return Op0;
+ // NOTE: could use computeKnownBits() / LazyValueInfo,
+ // but the cost-benefit analysis suggests it isn't worth it.
+
return nullptr;
}
OpenPOWER on IntegriCloud