[PATCH] [TTI/CostModel] improve TTI::getGEPCost and use it in CostModel::getInstructionCost

hfinkel at anl.gov hfinkel at anl.gov
Wed May 20 09:25:30 PDT 2015


================
Comment at: include/llvm/Analysis/TargetTransformInfoImpl.h:392
@@ +391,3 @@
+  unsigned getGEPCost(const Value *Ptr, ArrayRef<Value *> Operands) {
+    const GlobalValue *BaseGV = dyn_cast<GlobalValue>(Ptr);
+    bool HasBaseReg = (BaseGV == nullptr);
----------------
jingyue wrote:
> hfinkel wrote:
> > hfinkel wrote:
> > > You should call stripPointerCasts before doing the dyn_cast.
> > Should be dyn_cast_or_null b/c the cost model should not require the base pointer be known when estimating costs.
> Interesting -- when Ptr == nullptr, what is a good estimation? Fall back to using `getAddressComputationCost`? 
No, but there is another issue here. We're currently moving to give pointer an opaque type, and so you'll need to separately require a Type* on this interface. Please add that. Once you have the Type *, you should:

 1. assert that the type is equal to the pointer element type of the provided pointer (if it is provided) -- we'll remove this once we actually get rid of pointer element types, but for now we need the asserts
 2. use that type in the code below (there is a getGEPReturnType overload that takes the element type instead of the pointer itself)
 3. Make some default assumption for HasBaseReg (I think you should assume true).

http://reviews.llvm.org/D9819

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list