Commit 49479590 by Sudakshina Das Committed by Sudakshina Das

[PATCH PR82439][simplify-rtx] Simplify (x | y) == x -> (y & ~x) == 0

This patch add support for the missing transformation of
(x | y) == x -> (y & ~x) == 0. The transformation for (x & y) == x case
already exists in simplify-rtx.c since 2014 as of r218503 and this patch
only adds a couple of extra patterns for the IOR case. This benefits 
targets that have the BICS instruction to generate better code. For
targets that do not have the BICS instructions, it still results in
no worse code generation and gives out 2 instructions.

ChangeLog Entries:

*** gcc/ChangeLog ***

2018-01-05  Sudakshina Das  <sudi.das@arm.com>

	PR target/82439
	* simplify-rtx.c (simplify_relational_operation_1): Add simplifications
	of (x|y) == x for BICS pattern.

*** gcc/testsuite/ChangeLog ***

2018-01-05  Sudakshina Das  <sudi.das@arm.com>

	PR target/82439
	* gcc.target/aarch64/bics_5.c: New test.
	* gcc.target/arm/bics_5.c: Likewise.

From-SVN: r256275
parent bef52a68
2018-01-05 Sudakshina Das <sudi.das@arm.com>
PR target/82439
* simplify-rtx.c (simplify_relational_operation_1): Add simplifications
of (x|y) == x for BICS pattern.
2018-01-05 Jakub Jelinek <jakub@redhat.com> 2018-01-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/83605 PR tree-optimization/83605
......
...@@ -5051,34 +5051,38 @@ simplify_relational_operation_1 (enum rtx_code code, machine_mode mode, ...@@ -5051,34 +5051,38 @@ simplify_relational_operation_1 (enum rtx_code code, machine_mode mode,
simplify_gen_binary (XOR, cmp_mode, simplify_gen_binary (XOR, cmp_mode,
XEXP (op0, 1), op1)); XEXP (op0, 1), op1));
/* (eq/ne (and x y) x) simplifies to (eq/ne (and (not y) x) 0), which /* Simplify eq/ne (and/ior x y) x/y) for targets with a BICS instruction or
can be implemented with a BICS instruction on some targets, or constant folding if x/y is a constant. */
constant-folded if y is a constant. */
if ((code == EQ || code == NE) if ((code == EQ || code == NE)
&& op0code == AND && (op0code == AND || op0code == IOR)
&& rtx_equal_p (XEXP (op0, 0), op1)
&& !side_effects_p (op1) && !side_effects_p (op1)
&& op1 != CONST0_RTX (cmp_mode)) && op1 != CONST0_RTX (cmp_mode))
{ {
rtx not_y = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 1), cmp_mode); /* Both (eq/ne (and x y) x) and (eq/ne (ior x y) y) simplify to
rtx lhs = simplify_gen_binary (AND, cmp_mode, not_y, XEXP (op0, 0)); (eq/ne (and (not y) x) 0). */
if ((op0code == AND && rtx_equal_p (XEXP (op0, 0), op1))
|| (op0code == IOR && rtx_equal_p (XEXP (op0, 1), op1)))
{
rtx not_y = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 1),
cmp_mode);
rtx lhs = simplify_gen_binary (AND, cmp_mode, not_y, XEXP (op0, 0));
return simplify_gen_relational (code, mode, cmp_mode, lhs, return simplify_gen_relational (code, mode, cmp_mode, lhs,
CONST0_RTX (cmp_mode)); CONST0_RTX (cmp_mode));
} }
/* Likewise for (eq/ne (and x y) y). */ /* Both (eq/ne (and x y) y) and (eq/ne (ior x y) x) simplify to
if ((code == EQ || code == NE) (eq/ne (and (not x) y) 0). */
&& op0code == AND if ((op0code == AND && rtx_equal_p (XEXP (op0, 1), op1))
&& rtx_equal_p (XEXP (op0, 1), op1) || (op0code == IOR && rtx_equal_p (XEXP (op0, 0), op1)))
&& !side_effects_p (op1) {
&& op1 != CONST0_RTX (cmp_mode)) rtx not_x = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 0),
{ cmp_mode);
rtx not_x = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 0), cmp_mode); rtx lhs = simplify_gen_binary (AND, cmp_mode, not_x, XEXP (op0, 1));
rtx lhs = simplify_gen_binary (AND, cmp_mode, not_x, XEXP (op0, 1));
return simplify_gen_relational (code, mode, cmp_mode, lhs, return simplify_gen_relational (code, mode, cmp_mode, lhs,
CONST0_RTX (cmp_mode)); CONST0_RTX (cmp_mode));
}
} }
/* (eq/ne (bswap x) C1) simplifies to (eq/ne x C2) with C2 swapped. */ /* (eq/ne (bswap x) C1) simplifies to (eq/ne x C2) with C2 swapped. */
......
2018-01-05 Sudakshina Das <sudi.das@arm.com>
PR target/82439
* gcc.target/aarch64/bics_5.c: New test.
* gcc.target/arm/bics_5.c: Likewise.
2018-01-05 Jakub Jelinek <jakub@redhat.com> 2018-01-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/83605 PR tree-optimization/83605
......
/* { dg-do run } */
/* { dg-options "-O2 --save-temps -fno-inline" } */
extern void abort (void);
int
bics_si_test1 (int a, int b, int c)
{
if ((a | b) == a)
return a;
else
return c;
}
int
bics_si_test2 (int a, int b, int c)
{
if ((a | b) == b)
return b;
else
return c;
}
typedef long long s64;
s64
bics_di_test1 (s64 a, s64 b, s64 c)
{
if ((a | b) == a)
return a;
else
return c;
}
s64
bics_di_test2 (s64 a, s64 b, s64 c)
{
if ((a | b) == b)
return b;
else
return c;
}
int
main ()
{
int x;
s64 y;
x = bics_si_test1 (0xf00d, 0xf11f, 0);
if (x != 0)
abort ();
x = bics_si_test1 (0xf11f, 0xf00d, 0);
if (x != 0xf11f)
abort ();
x = bics_si_test2 (0xf00d, 0xf11f, 0);
if (x != 0xf11f)
abort ();
x = bics_si_test2 (0xf11f, 0xf00d, 0);
if (x != 0)
abort ();
y = bics_di_test1 (0x10001000f00dll, 0x12341000f00dll, 0ll);
if (y != 0)
abort ();
y = bics_di_test1 (0x12341000f00dll, 0x10001000f00dll, 0ll);
if (y != 0x12341000f00dll)
abort ();
y = bics_di_test2 (0x10001000f00dll, 0x12341000f00dll, 0ll);
if (y != 0x12341000f00dll)
abort ();
y = bics_di_test2 (0x12341000f00dll, 0x10001000f00dll, 0ll);
if (y != 0)
abort ();
return 0;
}
/* { dg-final { scan-assembler-times "bics\twzr, w\[0-9\]+, w\[0-9\]+" 2 } } */
/* { dg-final { scan-assembler-times "bics\txzr, x\[0-9\]+, x\[0-9\]+" 2 } } */
/* { dg-do run } */
/* { dg-options "-O2 --save-temps -fno-inline" } */
/* { dg-require-effective-target arm32 } */
extern void abort (void);
int
bics_si_test1 (int a, int b, int c)
{
if ((a | b) == a)
return a;
else
return c;
}
int
bics_si_test2 (int a, int b, int c)
{
if ((a | b) == b)
return b;
else
return c;
}
int
main ()
{
int x;
x = bics_si_test1 (0xf00d, 0xf11f, 0);
if (x != 0)
abort ();
x = bics_si_test1 (0xf11f, 0xf00d, 0);
if (x != 0xf11f)
abort ();
x = bics_si_test2 (0xf00d, 0xf11f, 0);
if (x != 0xf11f)
abort ();
x = bics_si_test2 (0xf11f, 0xf00d, 0);
if (x != 0)
abort ();
return 0;
}
/* { dg-final { scan-assembler-times "bics\tr\[0-9\]+, r\[0-9\]+, r\[0-9\]+" 2 } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment