[PATCH] Fix backward operands in call to isTruncateFree() and add asserts.

Steve King kingshizzle at gmail.com
Thu Mar 12 12:13:15 PDT 2015


In at least one case, DAGCombiner calls isTruncateFree() with operands in reverse order.  Fixed this and added asserts to the base class implementation to catch such problems in the future.

http://reviews.llvm.org/D8304

Files:
  include/llvm/Target/TargetLowering.h
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Index: include/llvm/Target/TargetLowering.h
===================================================================
--- include/llvm/Target/TargetLowering.h
+++ include/llvm/Target/TargetLowering.h
@@ -1462,16 +1462,10 @@
     return false;
   }
 
-  /// Return true if it's free to truncate a value of type FromTy to type
-  /// ToTy. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
+  /// Return true if it's free to truncate a value of type Ty1 to type
+  /// Ty2. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
   /// by referencing its sub-register AX.
-  virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const {
-    unsigned FromNumBits = FromTy->getPrimitiveSizeInBits();
-    unsigned ToNumBits = ToTy->getPrimitiveSizeInBits();
-    assert((FromNumBits > ToNumBits)
-            && "Can't truncate from small to large.");
-    (void)FromNumBits; // silence -Wunused
-    (void)ToNumBits;
+  virtual bool isTruncateFree(Type * /*Ty1*/, Type * /*Ty2*/) const {
     return false;
   }
 
@@ -1484,13 +1478,7 @@
     return false;
   }
 
-  virtual bool isTruncateFree(EVT FromVT, EVT ToVT) const {
-    unsigned FromNumBits = FromVT.getSizeInBits();
-    unsigned ToNumBits = ToVT.getSizeInBits();
-    assert((FromNumBits > ToNumBits)
-            && "Can't truncate from small to large.");
-    (void)FromNumBits; // silence -Wunused
-    (void)ToNumBits;
+  virtual bool isTruncateFree(EVT /*VT1*/, EVT /*VT2*/) const {
     return false;
   }
 
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9149,9 +9149,8 @@
     void addSliceGain(const LoadedSlice &LS) {
       // Each slice saves a truncate.
       const TargetLowering &TLI = LS.DAG->getTargetLoweringInfo();
-      // isTruncateFree(FromType,ToType)
-      if (!TLI.isTruncateFree(LS.Inst->getOperand(0).getValueType(),
-                                            LS.Inst->getValueType(0)))
+      if (!TLI.isTruncateFree(LS.Inst->getValueType(0),
+                              LS.Inst->getOperand(0).getValueType()))
         ++Truncates;
       // If there is a shift amount, this slice gets rid of it.
       if (LS.Shift)

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8304.21866.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150312/bfba206c/attachment.bin>


More information about the llvm-commits mailing list