Linear blend -> select InstCombine

Jean-Luc Duprat jduprat at apple.com
Fri May 3 18:35:23 PDT 2013


The attached patch provides instcombines for the following 3 cases:

A * (1 - (uitofp i1 C)) -> select C, 0, A
B * (uitofp i1 C) -> select C, B, 0
select C, 0, A + select C, B, 0 -> select C, B, A

These come up in code that has been hand-optimized from a select to a linear blend, on platforms where that may have mattered; that is we want to do the following transform:
A*(1 - uitofp i1 C) + B*(uitofp i1 C) -> select C, A, B

Test cases included in the patch, here are the 3 combine optimizations at work together:

$ cat foo.ll
define float @test3(float %A, float %B, i1 %C) {
EntryBlock:
  %cf = uitofp i1 %C to float
  %mc = fsub float 1.000000e+00, %cf
  %p1 = fmul fast float %A, %mc
  %p2 = fmul fast float %B, %cf
  %s1 = fadd fast float %p1, %p2
  ret float %s1
}

$ opt -instcombine -S fool.ll
define float @test3(float %A, float %B, i1 %C) {
EntryBlock:
  %s1 = select i1 %C, float %B, float %A
  ret float %s1
}


JL



More information about the llvm-commits mailing list