diff options
author | Paul Redmond <paul.redmond@intel.com> | 2013-02-12 15:21:21 +0000 |
---|---|---|
committer | Paul Redmond <paul.redmond@intel.com> | 2013-02-12 15:21:21 +0000 |
commit | 288604ed0c2dd9a66093c525c7525bb2e7ed91fc (patch) | |
tree | 00a8d2f029740f3cecb7876bd11b5af5bcc52700 /llvm/lib/CodeGen/SelectionDAG | |
parent | 71a4ab7141d7b201f0039f6d1f1ce7b8dd3b0430 (diff) | |
download | bcm5719-llvm-288604ed0c2dd9a66093c525c7525bb2e7ed91fc.tar.gz bcm5719-llvm-288604ed0c2dd9a66093c525c7525bb2e7ed91fc.zip |
PR14562 - Truncation of left shift became undef
DAGCombiner::ReduceLoadWidth was converting (trunc i32 (shl i64 v, 32))
into (shl i32 v, 32) into undef. To prevent this, check the shift count
against the final result size.
Patch by: Kevin Schoedel
Reviewed by: Nadav Rotem
llvm-svn: 174972
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 5b831499825..67fa39d9c2a 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -5163,8 +5163,15 @@ SDValue DAGCombiner::ReduceLoadWidth(SDNode *N) { EVT ShImmTy = getShiftAmountTy(Result.getValueType()); if (!isUIntN(ShImmTy.getSizeInBits(), ShLeftAmt)) ShImmTy = VT; - Result = DAG.getNode(ISD::SHL, N0.getDebugLoc(), VT, - Result, DAG.getConstant(ShLeftAmt, ShImmTy)); + // If the shift amount is as large as the result size (but, presumably, + // no larger than the source) then the useful bits of the result are + // zero; we can't simply return the shortened shift, because the result + // of that operation is undefined. + if (ShLeftAmt >= VT.getSizeInBits()) + Result = DAG.getConstant(0, VT); + else + Result = DAG.getNode(ISD::SHL, N0.getDebugLoc(), VT, + Result, DAG.getConstant(ShLeftAmt, ShImmTy)); } // Return the new loaded value. |