[PATCH] D17288: [CodeGenPrepare] Do select to branch transform when cmp's operand is expensive.

Junmo Park via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 17:15:07 PST 2016


flyingforyou added a comment.

Thanks Sanjay for comment.

We discussed about load-cmp heuristic in http://reviews.llvm.org/D16836. This is something likes load-cmp heuristic.

The main idea is if load takes so much cycles due to cache miss, we can get cmp's result after completing load. In this case, we can get huge benefit regarding transform select to branch. But recent OoO core has big cache(if we consider l1/l2/l3..) and h/w prefetcher... So we can avoid cache miss easily. This is what we talked about in http://reviews.llvm.org/D16836.

But this patch consider div(expensive instruction)-cmp case. Division is very expensive instruction which can take almost 17/30 cycles.(float/double case) Recent core's brach predictor miss penalty is 14 cycles(Ofcourse, it depends on uarch).
I think this case is what we really can hide expensive instruction cost.

I realized that test-case is too simple and it couldn't show what I really wanted. Sorry for miss reading.

  %div = fdiv float %a, %b                                  ; --> we need huge time for execution.
  %cmp = fcmp ogt float %div, %b
  %sel = select i1 %cmp, float %div, float 8.0    ;  --> We can't execute further.
  
  ; after this patch, select is changed to branch.
  
  %div = fdiv float %a, %b                                  ; --> we need huge time for execution.
  %cmp = fcmp ogt float %div, %b
  br i1 %cmp, label %select.end, label %select.false    ;  --> But, we can execute further by branch predictor.

Even if branch prediction is failed, we may not lost anything. Because fdiv float/double takes more cycles than branch prediction miss penalty.
And if branch prediction is correct, we can hide fdiv's execution cycles.

I think this is logically correct. But we need to test more. (test-suite, spec, commertial benchmarks...)

Junmo.


http://reviews.llvm.org/D17288





More information about the llvm-commits mailing list