On 9/26/23 18:50, Tamar Christina wrote:
Hi All,
For targets that allow conversion between int and float modes this adds a new
optimization transforming fneg (fabs (x)) into x | (1 << signbit(x)). Such
sequences are common in scientific code working with gradients.
The transformed instruction if the target has an inclusive-OR that takes an
immediate is both shorter an faster. For those that don't the immediate has
to be seperate constructed but this still ends up being faster as the immediate
construction is not on the critical path.
Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
Ok for master?
Thanks,
Tamar
gcc/ChangeLog:
PR tree-optimization/109154
* match.pd: Add new neg+abs rule.
gcc/testsuite/ChangeLog:
PR tree-optimization/109154
* gcc.target/aarch64/fneg-abs_1.c: New test.
* gcc.target/aarch64/fneg-abs_2.c: New test.
* gcc.target/aarch64/fneg-abs_3.c: New test.
* gcc.target/aarch64/fneg-abs_4.c: New test.
* gcc.target/aarch64/sve/fneg-abs_1.c: New test.
* gcc.target/aarch64/sve/fneg-abs_2.c: New test.
* gcc.target/aarch64/sve/fneg-abs_3.c: New test.
* gcc.target/aarch64/sve/fneg-abs_4.c: New test.
--- inline copy of patch --
diff --git a/gcc/match.pd b/gcc/match.pd
index
39c7ea1088f25538ed8bd26ee89711566141a71f..8ebde06dcd4b26d694826cffad0fb17e1136600a
100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9476,3 +9476,57 @@ and,
}
(if (full_perm_p)
(vec_perm (op@3 @0 @1) @3 @2))))))
+
+/* Transform fneg (fabs (X)) -> X | 1 << signbit (X). */
+
+(simplify
+ (negate (abs @0))
+ (if (FLOAT_TYPE_P (type)
+ /* We have to delay this rewriting till after forward prop because
otherwise
+ it's harder to do trigonometry optimizations. e.g. cos(-fabs(x)) is not
+ matched in one go. Instead cos (-x) is matched first followed by
cos(|x|).
+ The bottom op approach makes this rule match first and it's not untill
+ fwdprop that we match top down. There are manu such simplications so
we
Multiple typos this line. fwdprop->fwprop manu->many
simplications->simplifications.
OK with the typos fixed.
Thanks. I meant to say hi at the Cauldron, but never seemed to get away
long enough to find you..
jeff