[PATCH] middle-end: PR tree-optimization/21137: STRIP_NOPS avoids missed optimization.

Roger Sayle roger@nextmovesoftware.com
Fri Aug 21 16:55:29 GMT 2020


PR tree-optimization/21137 is now an old enhancement request pointing out
that an optimization I added back in 2006, to optimize "((x>>31)&64) != 0"
as "x < 0", doesn't fire in the presence of unanticipated type conversions.
The fix is to call STRIP_NOPS at the appropriate point.

I'd considered moving this transformation to match.pd, but it's a lot of
complex logic that (I suspect) would be just as ugly in match.pd as it is
in fold-const.c.

This patch has been tested on x86_64-pc-linux-gnu with a "make bootstrap"
and "make -k check" with no new failures.
Ok for mainline?

2020-08-21  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	PR tree-optimization/21137
	* gcc/fold-const.c (fold_binary_loc) [NE_EXPR/EQ_EXPR]: Call
	STRIP_NOPS when checking whether to simplify ((x>>C1)&C2) != 0.

gcc/testsuite/ChangeLog
	PR tree-optimization/21137
	* gcc.dg/pr21137.c: New test.


Thanks in advance,
Roger
--
Roger Sayle
NextMove Software
Cambridge, UK

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchc.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200821/eeddf7d5/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchcb.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200821/eeddf7d5/attachment-0001.txt>


More information about the Gcc-patches mailing list