public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH PR82439][simplify-rtx] Simplify (x | y) == x -> (y & ~x) == 0
@ 2018-01-03 13:57 Sudakshina Das
  2018-01-03 14:38 ` Segher Boessenkool
  2018-01-04 18:30 ` Jeff Law
  0 siblings, 2 replies; 5+ messages in thread
From: Sudakshina Das @ 2018-01-03 13:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd

Hi

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.

Citing the example given in PR82439 :

Simple testcase (f1 should generate the same as f2):

int f1(int x, int y) { return (x | y) == x; }
int f2(int x, int y) { return (y & ~x) == 0; }

f1:
	orr	w1, w0, w1
	cmp	w1, w0
	cset	w0, eq
	ret
f2:
	bics	wzr, w1, w0
	cset	w0, eq
	ret

This benefits targets that have the BICS instruction to generate better 
code. Wilco helped me in showing that even in targets that do not have 
the BICS instruction, this is no worse and gives out 2 instructions.
For example in x86:

0000000000000000 <f1>:
    0:	09 fe                	or     %edi,%esi
    2:	31 c0                	xor    %eax,%eax
    4:	39 fe                	cmp    %edi,%esi
    6:	0f 94 c0             	sete   %al
    9:	c3                   	retq

0000000000000010 <f2>:
   10:	f7 d7                	not    %edi
   12:	31 c0                	xor    %eax,%eax
   14:	85 f7                	test   %esi,%edi
   16:	0f 94 c0             	sete   %al
   19:	c3                   	retq

Testing done: Checked for regressions on bootstrapped 
aarch64-none-linux-gnu and arm-none-linux-gnueabihf and added new test 
cases.
Is this ok for trunk?

Sudi

ChangeLog Entries:

*** gcc/ChangeLog ***

2017-01-03  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 ***

2017-01-03  Sudakshina Das  <sudi.das@arm.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-05 10:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-03 13:57 [PATCH PR82439][simplify-rtx] Simplify (x | y) == x -> (y & ~x) == 0 Sudakshina Das
2018-01-03 14:38 ` Segher Boessenkool
2018-01-03 15:00   ` Sudakshina Das
2018-01-04 18:30 ` Jeff Law
2018-01-05 10:47   ` Sudakshina Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).