On 8/3/2022 2:44 PM, Prathamesh Kulkarni via Gcc-patches wrote:
On Thu, 4 Aug 2022 at 00:41, Sam Feifer via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
This patch adds a new optimization to match.pd. The pattern, -x & 1,
now gets simplified to x & 1, reducing the number of instructions
produced.
Hi Sam,
No comments on patch, but wondering if we can similarly add another pattern to
simplify abs(x) & 1 -> x & 1 ?
Currently we don't appear to do it on GIMPLE:

__attribute__((noipa))
int f1 (int x)
{
   return __builtin_abs (x) & 1;
}

.optimized dump shows:
   _1 = ABS_EXPR <x_2(D)>;
   _3 = _1 & 1;
   return _3;

altho combine simplifies it to x & 1 on RTL, resulting in code-gen:
f1:
         and     w0, w0, 1
         ret
Doesn't the abs(x) & mask simplify to x & mask for any mask where the sign bit of x is off -- including cases where mask isn't necessarily a compile-time constant, but we have range data which allows us to know that x's sign bit is off in mask.

jeff



Reply via email to