[llvm-commits] [llvm] r97616 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/Transforms/InstCombine/InstCombineAndOrXor.cpp test/CodeGen/X86/and-or-fold.ll test/Transforms/InstCombine/xor2.ll

Eli Friedman eli.friedman at gmail.com
Tue Mar 2 17:43:17 PST 2010


On Tue, Mar 2, 2010 at 4:35 PM, Bill Wendling <isanbard at gmail.com> wrote:
> Author: void
> Date: Tue Mar  2 18:35:56 2010
> New Revision: 97616
>
> URL: http://llvm.org/viewvc/llvm-project?rev=97616&view=rev
> Log:
> This test case:
>
> long test(long x) { return (x & 123124) | 3; }
>
> Currently compiles to:
>
> _test:
>        orl     $3, %edi
>        movq    %rdi, %rax
>        andq    $123127, %rax
>        ret
>
> This is because instruction and DAG combiners canonicalize
>
>  (or (and x, C), D) -> (and (or, D), (C | D))
>
> However, this is only profitable if (C & D) != 0. It gets in the way of the
> 3-addressification because the input bits are known to be zero.

To encourage canonicalization, we should transform either
((x&C)|D)->((x|D)&(C|D)), or ((x|C)&D) -> ((X&D)|(C&D)).  If it
appears the form with the or on the outside is better, we should use
it unconditionally.

-Eli




More information about the llvm-commits mailing list