aboutsummaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-08-19 17:56:46 -0700
committerAndrew Pinski <apinski@marvell.com>2023-08-25 09:34:59 -0700
commit6df8dcec7196e42ca2eed69e1ae455bae8d0fe93 (patch)
treeffaee6798eb0a9e23da78484826ae97975b5b728 /gcc/match.pd
parent4024ddbe50c2d1cb54c75304c72817d3fc63cdb6 (diff)
downloadgcc-6df8dcec7196e42ca2eed69e1ae455bae8d0fe93.zip
gcc-6df8dcec7196e42ca2eed69e1ae455bae8d0fe93.tar.gz
gcc-6df8dcec7196e42ca2eed69e1ae455bae8d0fe93.tar.bz2
MATCH: `a | C -> C` when we know that `a & ~C == 0`
Even though this is handled by other code inside both VRP and CCP, sometimes we want to optimize this outside of VRP and CCP. An example is given in PR 106677 where phiopt will happen after VRP (which removes a cast for a comparison) and then phiopt will optimize the phi to be `a | 1` which can then be optimized to `1` due to this patch. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note Similar code already exists in simplify_rtx for the RTL level; it was moved from combine to simplify_rtx in r0-72539-gbd1ef757767f6d. gcc/ChangeLog: * match.pd (`a | C -> C`): New pattern.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index cf0bb3a..d9f35e9 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1456,6 +1456,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0)
@0))
+/* x | C -> C if we know that x & ~C == 0. */
+(simplify
+ (bit_ior SSA_NAME@0 INTEGER_CST@1)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0)
+ @1))
#endif
/* ~(~X - Y) -> X + Y and ~(~X + Y) -> X - Y. */