diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-05-12 03:07:40 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-05-12 03:07:40 +0000 |
commit | 96f0d383a7adf48d643fbcd85a8595042ff8e84e (patch) | |
tree | d6c2bddd37496ba1bf58b85e398e914427b1cb76 /llvm/lib/Transforms | |
parent | 8300272823108eb17f01af51c4d54ef5018a5e6d (diff) | |
download | bcm5719-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/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 16 |
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)); |