[llvm-commits] [llvm] r159230 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineAddSub.cpp test/Transforms/InstCombine/mul.ll test/Transforms/InstCombine/zext-bool-add-sub.ll

Eli Friedman eli.friedman at gmail.com
Tue Jun 26 15:10:02 PDT 2012


On Tue, Jun 26, 2012 at 3:03 PM, Evan Cheng <evan.cheng at apple.com> wrote:
> Author: evancheng
> Date: Tue Jun 26 17:03:13 2012
> New Revision: 159230
>
> URL: http://llvm.org/viewvc/llvm-project?rev=159230&view=rev
> Log:
> Remove a instcombine transform that (no longer?) makes sense:
>    // C - zext(bool) -> bool ? C - 1 : C
>    if (ZExtInst *ZI = dyn_cast<ZExtInst>(Op1))
>      if (ZI->getSrcTy()->isIntegerTy(1))
>        return SelectInst::Create(ZI->getOperand(0), SubOne(C), C);
>
> This ends up forming sext i1 instructions that codegen to terrible code. e.g.
> int blah(_Bool x, _Bool y) {
>  return (x - y) + 1;
> }
> =>
>        movzbl  %dil, %eax
>        movzbl  %sil, %ecx
>        shll    $31, %ecx
>        sarl    $31, %ecx
>        leal    1(%rax,%rcx), %eax
>        ret
>
>
> Without the rule, llvm now generates:
>        movzbl  %sil, %ecx
>        movzbl  %dil, %eax
>        incl    %eax
>        subl    %ecx, %eax
>        ret
>
> It also helps with ARM (and pretty much any target that doesn't have a sext i1 :-).
>
> The transformation was done as part of Eli's r75531. He has given the ok to
> remove it.

If you're convinced the form with zext should be the canonical form,
you should make sure we transform the equivalent constructs with sext
and select to the form with zext.

-Eli




More information about the llvm-commits mailing list