From 96f0d383a7adf48d643fbcd85a8595042ff8e84e Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 12 May 2016 03:07:40 +0000 Subject: [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 --- llvm/lib/Transforms/Scalar/SCCP.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'llvm/lib/Transforms/Scalar/SCCP.cpp') 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)); -- cgit v1.2.3