]> granicus.if.org Git - llvm/commitdiff
Convert an APInt to int64_t properly in TTI::getGEPCost().
authorJustin Lebar <jlebar@google.com>
Wed, 4 Oct 2017 20:47:33 +0000 (20:47 +0000)
committerJustin Lebar <jlebar@google.com>
Wed, 4 Oct 2017 20:47:33 +0000 (20:47 +0000)
Summary:
If the pointer width is 32 bits and the calculated GEP offset is
negative, we call APInt::getLimitedValue(), which does a
*zero*-extension of the offset.  That's wrong -- we should do an sext.

Fixes a bug introduced in rL314362 and found by Evgeny Astigeevich.

Reviewers: efriedma

Subscribers: sanjoy, javed.absar, llvm-commits, eastig

Differential Revision: https://reviews.llvm.org/D38557

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

include/llvm/Analysis/TargetTransformInfoImpl.h
test/Analysis/CostModel/ARM/gep.ll

index 2434f593bbbd97015037f2df13f0a7ea4a49f93c..905609e1afcd5b8fd64dd34b1e2309a6f03283e9 100644 (file)
@@ -720,10 +720,10 @@ public:
     // Assumes the address space is 0 when Ptr is nullptr.
     unsigned AS =
         (Ptr == nullptr ? 0 : Ptr->getType()->getPointerAddressSpace());
+
     if (static_cast<T *>(this)->isLegalAddressingMode(
             TargetType, const_cast<GlobalValue *>(BaseGV),
-            static_cast<int64_t>(BaseOffset.getLimitedValue()), HasBaseReg,
-            Scale, AS))
+            BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS))
       return TTI::TCC_Free;
     return TTI::TCC_Basic;
   }
index 9d74da4c2d3b054fc94f9724514affa876cc48c0..12e314e24073d64e3396995637f16706702b3c88 100644 (file)
@@ -83,5 +83,8 @@ define void @test_geps(i32 %i) {
 ;CHECK: cost of 1 for instruction: {{.*}} getelementptr inbounds <4 x double>, <4 x double>*
   %c12 = getelementptr inbounds <4 x double>, <4 x double>* undef, i32 %i
 
+;CHECK: cost of 0 for instruction: {{.*}} getelementptr inbounds i8, i8*
+  %d0 = getelementptr inbounds i8, i8* undef, i32 -1
+
   ret void
 }