[llvm] r174972 - PR14562 - Truncation of left shift became undef

Paul Redmond paul.redmond at intel.com
Tue Feb 12 07:21:22 PST 2013


Author: predmond
Date: Tue Feb 12 09:21:21 2013
New Revision: 174972

URL: http://llvm.org/viewvc/llvm-project?rev=174972&view=rev
Log:
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

Added:
    llvm/trunk/test/CodeGen/X86/pr14562.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=174972&r1=174971&r2=174972&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Feb 12 09:21:21 2013
@@ -5163,8 +5163,15 @@ SDValue DAGCombiner::ReduceLoadWidth(SDN
     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.

Added: llvm/trunk/test/CodeGen/X86/pr14562.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr14562.ll?rev=174972&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr14562.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pr14562.ll Tue Feb 12 09:21:21 2013
@@ -0,0 +1,15 @@
+; RUN: llc < %s -march=x86 | FileCheck %s
+
+ at temp1 = global i64 -77129852189294865, align 8
+
+define void @foo() nounwind {
+  %x = load i64* @temp1, align 8
+  %s = shl i64 %x, 32
+  %t = trunc i64 %s to i32
+  %z = zext i32 %t to i64
+  store i64 %z, i64* @temp1, align 8
+; CHECK: movl $0, temp1+4
+; CHECK: movl $0, temp1
+  ret void
+}
+





More information about the llvm-commits mailing list