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

hfinkel at anl.gov hfinkel at anl.gov
Mon May 18 00:43:00 PDT 2015


================
Comment at: include/llvm/Analysis/TargetTransformInfo.h:139
@@ -138,3 +138,3 @@
   /// the GEP operation.
-  unsigned getGEPCost(const Value *Ptr, ArrayRef<const Value *> Operands) const;
+  unsigned getGEPCost(const Value *Ptr, ArrayRef<Value *> Operands) const;
 
----------------
I see no reason to change the interface here. We can localize the const_casts to the implementation, instead of forcing them into all callers that have const references/pointers.


================
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);
----------------
You should call stripPointerCasts before doing the dyn_cast.

================
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);
----------------
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.

================
Comment at: lib/Analysis/CostModel.cpp:386
@@ -385,2 +385,3 @@
   switch (I->getOpcode()) {
   case Instruction::GetElementPtr:{
+    return TTI->getUserCost(I);
----------------
You don't need the { } here any longer.

http://reviews.llvm.org/D9819

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






More information about the llvm-commits mailing list