[PATCH] D17353: Set minimum cost of speculating an instruction.

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 17 22:00:24 PST 2016


hfinkel added a subscriber: hfinkel.

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:255
@@ +254,3 @@
+  if (Cost < TargetTransformInfo::TCC_Basic)
+    Cost = TargetTransformInfo::TCC_Basic;
+  return Cost;
----------------
danielcdh wrote:
> davidxl wrote:
> > My real question is why TTI.getUserCost(I) returns the wrong cost here :)
> For this specific case, it's that GEP operator is mostly considered free (as soon as the addressing mode is legal). The reasoning is that if you dereference the output of GEP operator, the memory instruction can have the addressing encoded. But here GEP operator is not immediately used by a memory op. Instead, it's used later in other basic block, and the GEP operation actually translated to a real LEA instruction, thus it is not free.
> 
> I don't think it's quite right to set most GEP operator as 0-cost. But just by looking at the GEP operator itself, it's hard to tell whether it will be encoded into the memory op, or need to have separate instruction for it. In this case, it would be better to be conservative.
> 
> So what should I do? Change GEP operator's cost to TCC_Basic for all cases?
> So what should I do? Change GEP operator's cost to TCC_Basic for all cases?

Please don't do that; you'll be making the common case worse. The right answer is to look at the addressing mode and make a more-intelligent decision.

As it turns out, I recall having a patch that did something like this (see gep-add-cost-v2.patch in http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20140303/206866.html). We never really finished discussing it, but you might see if something like that patch helps here too.


http://reviews.llvm.org/D17353





More information about the llvm-commits mailing list