This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Reassociate X == CST1 || X == CST2 if popcount (CST2 - CST1) == 1 into ((X - CST1) & ~(CST2 - CST1)) == 0
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Zhenqiang Chen <zhenqiang dot chen at arm dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 15 Oct 2013 10:12:39 +0200
- Subject: Re: [PATCH] Reassociate X == CST1 || X == CST2 if popcount (CST2 - CST1) == 1 into ((X - CST1) & ~(CST2 - CST1)) == 0
- Authentication-results: sourceware.org; auth=none
- References: <000001ce91b3$0a947cc0$1fbd7640$ at arm dot com> <20131010111245 dot GE30970 at tucnak dot zalov dot cz> <000001cec6ef$e881b0e0$b98512a0$ at arm dot com> <20131012073934 dot GB30970 at tucnak dot zalov dot cz> <000001cec8ac$6df29e70$49d7db50$ at arm dot com> <20131014084901 dot GG30970 at tucnak dot zalov dot cz> <000001cec97c$30182720$90487560$ at arm dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Oct 15, 2013 at 03:57:23PM +0800, Zhenqiang Chen wrote:
> Is it OK?
Ok, except two comments apparently still need updating.
+/* Optimize X == CST1 || X == CST2
+ if popcount (CST1 ^ CST2) == 1 into
+ (X & ~(CST1 ^ CST2)) == (CST1 & ~(CST1 ^ CST2)).
+ Similarly for ranges. E.g.
+ X != 2 && X != 3 && X != 10 && X != 11
+ will be transformed by the previous optimization into
+ (X - 2U) <= 1U && (X - 10U) <= 1U
+ and this loop can transform that into
+ ((X & ~8) - 2U) <= 1U. */
Here the example is using != and &&, so it is transformed into:
!((X - 2U) <= 1U || (X - 10U) <= 1U)
(everything is negated at the end, and note || instead of &&,
with && it could fold into !(0))
and finally into:
!(((X & ~8) - 2U) <= 1U)
Or alternatively change the first expression into:
X == 2 || X == 3 || X == 10 || X == 11
and the second to:
(X - 2U) <= 1U || (X - 10U) <= 1U
and the third keep as is.
+/* Optimize X == CST1 || X == CST2
+ if popcount (CST2 - CST1) == 1 into
+ ((X - CST1) & ~(CST2 - CST1)) == 0.
+ Similarly for ranges. E.g.
+ X == 43 || X == 76 || X == 44 || X == 78 || X == 77 || X == 46
+ || X == 75 || X == 45
+ will be transformed by the previous optimization into
+ (X - 43U) <= 3U && (X - 75U) <= 3U
+ and this loop can transform that into
+ ((X - 43U) & ~(75U - 43U)) <= 3U. */
Here the example is using == and ||, so the only wrong thing in there
is that the second expression should be
(X - 43U) <= 3U || (X - 75U) <= 3U
Ok with those changes.
Jakub