[llvm] r221693 - LLVM incorrectly folds xor into select
Jonathan Roelofs
jonathan at codesourcery.com
Tue Nov 11 09:48:14 PST 2014
On 11/11/14 10:36 AM, Oliver Stannard wrote:
> Author: olista01
> Date: Tue Nov 11 11:36:01 2014
> New Revision: 221693
>
> URL: http://llvm.org/viewvc/llvm-project?rev=221693&view=rev
> Log:
> LLVM incorrectly folds xor into select
>
> LLVM replaces the SelectionDAG pattern (xor (set_cc cc x y) 1) with
> (set_cc !cc x y), which is only correct when the xor has type i1.
> Instead, we should check that the constant operand to the xor is all
> ones.
>
> +
> +; Do not fold the xor into the select
> +define i32 @t15(i32 %p1, i32 %p2, i32 %p3) {
> +entry:
> +; ARM: cmp r0, #8
> +; ARM: mov{{(le|gt)}} [[REG:r[0-9]+]], {{r[0-9]+}}
> +; ARM: eor r0, [[REG]], #1
> +
> +; T2: cmp r0, #8
> +; T2: it [[CC:(le|gt)]]
> +; T2: mov[[CC]] [[REG:r[0-9]+]], {{r[0-9]+}}
> +; T2: eor r0, [[REG:r[0-9]+]], #1
> + %cmp = icmp sgt i32 %p1, 8
> + %a = select i1 %cmp, i32 %p2, i32 %p3
> + %xor = xor i32 %a, 1
> + ret i32 %xor
> +}
>
Oliver,
I'm not quite sure I understand how this transformation really works, or I'm
seriously confused by the testcase. Does the new test case fail without the rest
of the patch? Shouldn't the xor be on the condition code, and not the result of
the select?
Would you mind also adding tests for what you expect these two to be lowered as:
define i32 @t15_2(i32 %p1, i32 %p2, i32 %p3) {
entry:
%cmp = icmp sgt i32 %p1, 8
%a = select i1 %cmp, i32 %p2, i32 %p3
%xor = xor i32 %a, -1
ret i32 %xor
}
define signext i1 @t15_3(i32 %p1, signext i1 %p2, signext i1 %p3) {
entry:
%cmp = icmp sgt i32 %p1, 8
%a = select i1 %cmp, i1 %p2, i1 %p3
%xor = xor i1 %a, 1
ret i1 %xor
}
Cheers,
Jon
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded
More information about the llvm-commits
mailing list