[PATCH] D53161: Fix some cases where the index size was used instead of the pointer size

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 12:29:58 PDT 2018


nhaehnle created this revision.
nhaehnle added reviewers: arsenm, theraven, craig.topper, sanjoy, delena.
Herald added subscribers: arphaman, wdng.
nhaehnle added a dependent revision: D53162: [DataLayout] Add bit width of pointers to global values.

r325102 introduced the split between pointer size (number of bytes / bits
of a pointer) and index size (number of bytes / bits that are canonically
used for GEP index operands).

This patch fixes a bunch of locations around ValueTracking where the
index size was incorrectly used for pointer types.

There are no new or fixed test cases. This patch simply fixes a
conceptual error that I noticed while working on ValueTracking for
pointers (for which I will submit a separate patch).

Change-Id: Ic63c2db644b53dc036ea2d1f037dafea4ad10b02


Repository:
  rL LLVM

https://reviews.llvm.org/D53161

Files:
  lib/Analysis/ValueTracking.cpp
  lib/Transforms/InstCombine/InstCombineCompares.cpp


Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4284,7 +4284,7 @@
   // Get scalar or pointer size.
   unsigned BitWidth = Ty->isIntOrIntVectorTy()
                           ? Ty->getScalarSizeInBits()
-                          : DL.getIndexTypeSizeInBits(Ty->getScalarType());
+                          : DL.getPointerTypeSizeInBits(Ty->getScalarType());
 
   if (!BitWidth)
     return nullptr;
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -90,7 +90,7 @@
   if (unsigned BitWidth = Ty->getScalarSizeInBits())
     return BitWidth;
 
-  return DL.getIndexTypeSizeInBits(Ty);
+  return DL.getPointerTypeSizeInBits(Ty);
 }
 
 namespace {
@@ -1120,13 +1120,9 @@
   case Instruction::Trunc: {
     Type *SrcTy = I->getOperand(0)->getType();
 
-    unsigned SrcBitWidth;
     // Note that we handle pointer operands here because of inttoptr/ptrtoint
     // which fall through here.
-    Type *ScalarTy = SrcTy->getScalarType();
-    SrcBitWidth = ScalarTy->isPointerTy() ?
-      Q.DL.getIndexTypeSizeInBits(ScalarTy) :
-      Q.DL.getTypeSizeInBits(ScalarTy);
+    unsigned SrcBitWidth = getBitWidth(SrcTy, Q.DL);
 
     assert(SrcBitWidth && "SrcBitWidth can't be zero");
     Known = Known.zextOrTrunc(SrcBitWidth);
@@ -1582,9 +1578,7 @@
           V->getType()->isPtrOrPtrVectorTy()) &&
          "Not integer or pointer type!");
 
-  Type *ScalarTy = V->getType()->getScalarType();
-  unsigned ExpectedWidth = ScalarTy->isPointerTy() ?
-    Q.DL.getIndexTypeSizeInBits(ScalarTy) : Q.DL.getTypeSizeInBits(ScalarTy);
+  unsigned ExpectedWidth = getBitWidth(V->getType(), Q.DL);
   assert(ExpectedWidth == BitWidth && "V and Known should have same BitWidth");
   (void)BitWidth;
   (void)ExpectedWidth;
@@ -2021,7 +2015,7 @@
         return true;
   }
 
-  unsigned BitWidth = getBitWidth(V->getType()->getScalarType(), Q.DL);
+  unsigned BitWidth = getBitWidth(V->getType(), Q.DL);
 
   // X | Y != 0 if X != 0 or Y != 0.
   Value *X = nullptr, *Y = nullptr;
@@ -2287,10 +2281,7 @@
   // in V, so for undef we have to conservatively return 1.  We don't have the
   // same behavior for poison though -- that's a FIXME today.
 
-  Type *ScalarTy = V->getType()->getScalarType();
-  unsigned TyBits = ScalarTy->isPointerTy() ?
-    Q.DL.getIndexTypeSizeInBits(ScalarTy) :
-    Q.DL.getTypeSizeInBits(ScalarTy);
+  unsigned TyBits = getBitWidth(V->getType(), Q.DL);
 
   unsigned Tmp, Tmp2;
   unsigned FirstAnswer = 1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53161.169271.patch
Type: text/x-patch
Size: 2746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181011/a6a8975a/attachment.bin>


More information about the llvm-commits mailing list