add ShouldChangeType() variant that takes bitwidths
authorSanjay Patel <spatel@rotateright.com>
Mon, 21 Sep 2015 16:09:37 +0000 (16:09 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 21 Sep 2015 16:09:37 +0000 (16:09 +0000)
This is more efficient for cases like D12965 where we already have widths.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248170 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineInternal.h
lib/Transforms/InstCombine/InstructionCombining.cpp

index 9f5cdcbb32970a56824f60196262e72e40ea521f..dbaa5a88ee3fccabb9dd2a23e8c32490d4a2729c 100644 (file)
@@ -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;
index 8c70a1c5895d3c96b6377a6e3d6b8db09424a437..72548dc69ca308bf51e03e496c401f65fc890522 100644 (file)
@@ -80,14 +80,12 @@ Value *InstCombiner::EmitGEPOffset(User *GEP) {
   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 *From, Type *To) const {
   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