[PATCH] [InstCombine] Teach how to fold a select into a cttz/ctlz with the 'is_zero_undef' flag cleared.

Andrea Di Biagio Andrea_DiBiagio at sn.scee.net
Fri Jan 9 10:41:47 PST 2015


Hi Pete,

In http://reviews.llvm.org/D6891#106740, @pete wrote:

> Hi Andrea
>
> Is this intended to replace the work in CodeGenPrepare:r225274?


No, It applies to a different scenario where the cttz/ctlz is always evaluated.

Something like:

  unsigned int foo(unsigned int x) {
    unsigned int count = __builtin_ctz(x);
    return x ? count : 32;
  }

Where the count trailing zeroes is always evaluated before reaching the conditional statement (which is then converted into a select).

The logic added in CodeGenPrepare would work in a different scenario (see below):

  unsigned int bar(unsigned int x) {
    return x ? __builtin_ctz(x) : 32;
  }

In this case, the builtin call is not always executed since it is not dominating the control flow (it is in the 'then' part). Depending on the target, it may or may not be beneficial to speculate that builtin call.

> If you match this to a single intrinsic call in instcombine then it would be relatively simple for SimplifyCFG to then speculate it with existing code.  Then we can remove the code from CGP?


The problem with implementing that logic into SimplifyCFG is that we need to query the target to check if calls to cttz/ctlz are cheap to speculate. Therefore, in code review http://reviews.llvm.org/D6679 it was suggested by the reviewers to move that logic into CodeGenPrepare.

I hope this clears up any misunderstanding.

-Andrea

> Thanks,

> Pete





http://reviews.llvm.org/D6891

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






More information about the llvm-commits mailing list