[llvm] r248170 - add ShouldChangeType() variant that takes bitwidths

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 09:09:37 PDT 2015


Author: spatel
Date: Mon Sep 21 11:09:37 2015
New Revision: 248170

URL: http://llvm.org/viewvc/llvm-project?rev=248170&view=rev
Log:
add ShouldChangeType() variant that takes bitwidths

This is more efficient for cases like D12965 where we already have widths.


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=248170&r1=248169&r2=248170&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Mon Sep 21 11:09:37 2015
@@ -341,6 +341,7 @@ public:
                                  const unsigned SIOpd);
 
 private:
+  bool ShouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
   bool ShouldChangeType(Type *From, Type *To) const;
   Value *dyn_castNegVal(Value *V) const;
   Value *dyn_castFNegVal(Value *V, bool NoSignedZero = false) const;

Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=248170&r1=248169&r2=248170&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Mon Sep 21 11:09:37 2015
@@ -80,14 +80,12 @@ Value *InstCombiner::EmitGEPOffset(User
   return llvm::EmitGEPOffset(Builder, DL, GEP);
 }
 
-/// Return true if it is desirable to convert a computation from 'From' to 'To'.
+/// Return true if it is desirable to convert an integer computation from a
+/// given bit width to a new bit width.
 /// We don't want to convert from a legal to an illegal type for example or from
 /// a smaller to a larger illegal type.
-bool InstCombiner::ShouldChangeType(Type *From, Type *To) const {
-  assert(From->isIntegerTy() && To->isIntegerTy());
-
-  unsigned FromWidth = From->getPrimitiveSizeInBits();
-  unsigned ToWidth = To->getPrimitiveSizeInBits();
+bool InstCombiner::ShouldChangeType(unsigned FromWidth,
+                                    unsigned ToWidth) const {
   bool FromLegal = DL.isLegalInteger(FromWidth);
   bool ToLegal = DL.isLegalInteger(ToWidth);
 
@@ -104,6 +102,17 @@ bool InstCombiner::ShouldChangeType(Type
   return true;
 }
 
+/// Return true if it is desirable to convert a computation from 'From' to 'To'.
+/// We don't want to convert from a legal to an illegal type for example or from
+/// a smaller to a larger illegal type.
+bool InstCombiner::ShouldChangeType(Type *From, Type *To) const {
+  assert(From->isIntegerTy() && To->isIntegerTy());
+
+  unsigned FromWidth = From->getPrimitiveSizeInBits();
+  unsigned ToWidth = To->getPrimitiveSizeInBits();
+  return ShouldChangeType(FromWidth, ToWidth);
+}
+
 // Return true, if No Signed Wrap should be maintained for I.
 // The No Signed Wrap flag can be kept if the operation "B (I.getOpcode) C",
 // where both B and C should be ConstantInts, results in a constant that does




More information about the llvm-commits mailing list