[llvm] r314935 - Convert an APInt to int64_t properly in TTI::getGEPCost().

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 13:47:34 PDT 2017


Author: jlebar
Date: Wed Oct  4 13:47:33 2017
New Revision: 314935

URL: http://llvm.org/viewvc/llvm-project?rev=314935&view=rev
Log:
Convert an APInt to int64_t properly in TTI::getGEPCost().

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

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

Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=314935&r1=314934&r2=314935&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h Wed Oct  4 13:47:33 2017
@@ -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;
   }

Modified: llvm/trunk/test/Analysis/CostModel/ARM/gep.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/ARM/gep.ll?rev=314935&r1=314934&r2=314935&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/ARM/gep.ll (original)
+++ llvm/trunk/test/Analysis/CostModel/ARM/gep.ll Wed Oct  4 13:47:33 2017
@@ -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
 }




More information about the llvm-commits mailing list