summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-05-12 03:07:40 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-05-12 03:07:40 +0000
commit96f0d383a7adf48d643fbcd85a8595042ff8e84e (patch)
treed6c2bddd37496ba1bf58b85e398e914427b1cb76 /llvm/lib
parent8300272823108eb17f01af51c4d54ef5018a5e6d (diff)
downloadbcm5719-llvm-96f0d383a7adf48d643fbcd85a8595042ff8e84e.tar.gz
bcm5719-llvm-96f0d383a7adf48d643fbcd85a8595042ff8e84e.zip
[SCCP] Resolve shifts beyond the bitwidth to undef
Shifts beyond the bitwidth are undef but SCCP resolved them to zero. Instead, DTRT and resolve them to undef. This reimplements the transform which caused PR27712. llvm-svn: 269269
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 75414ef3864..c75c948329c 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1416,6 +1416,14 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// X >>a undef -> undef.
if (Op1LV.isUndefined()) break;
+ // Shifting by the bitwidth or more is undefined.
+ if (Op1LV.isConstant()) {
+ auto *ShiftAmt = Op1LV.getConstantInt();
+ if (ShiftAmt->getLimitedValue() >=
+ ShiftAmt->getType()->getScalarSizeInBits())
+ break;
+ }
+
// undef >>a X -> all ones
markForcedConstant(&I, Constant::getAllOnesValue(ITy));
return true;
@@ -1425,6 +1433,14 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// X >> undef -> undef.
if (Op1LV.isUndefined()) break;
+ // Shifting by the bitwidth or more is undefined.
+ if (Op1LV.isConstant()) {
+ auto *ShiftAmt = Op1LV.getConstantInt();
+ if (ShiftAmt->getLimitedValue() >=
+ ShiftAmt->getType()->getScalarSizeInBits())
+ break;
+ }
+
// undef << X -> 0
// undef >> X -> 0
markForcedConstant(&I, Constant::getNullValue(ITy));
OpenPOWER on IntegriCloud