diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2024-05-18 11:55:58 -0700 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2024-05-20 14:39:20 -0700 |
commit | 9ff8f041331ef8b56007fb3c4d41d76f9850010d (patch) | |
tree | 3cb975d412f9668a702b143775d6b73d19679de2 /gcc/tree-ssa-phiopt.cc | |
parent | 38d1761c0c94b77a081ccc180d6e039f7a670468 (diff) | |
download | gcc-9ff8f041331ef8b56007fb3c4d41d76f9850010d.zip gcc-9ff8f041331ef8b56007fb3c4d41d76f9850010d.tar.gz gcc-9ff8f041331ef8b56007fb3c4d41d76f9850010d.tar.bz2 |
PHIOPT: Don't transform minmax if middle bb contains a phi [PR115143]
The problem here is even if last_and_only_stmt returns a statement,
the bb might still contain a phi node which defines a ssa name
which is used in that statement so we need to add a check to make sure
that the phi nodes are empty for the middle bbs in both the
`CMP?MINMAX:MINMAX` case and the `CMP?MINMAX:B` cases.
Bootstrapped and tested on x86_64_linux-gnu with no regressions.
PR tree-optimization/115143
gcc/ChangeLog:
* tree-ssa-phiopt.cc (minmax_replacement): Check for empty
phi nodes for middle bbs for the case where middle bb is not empty.
gcc/testsuite/ChangeLog:
* gcc.c-torture/compile/pr115143-1.c: New test.
* gcc.c-torture/compile/pr115143-2.c: New test.
* gcc.c-torture/compile/pr115143-3.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc/tree-ssa-phiopt.cc')
-rw-r--r-- | gcc/tree-ssa-phiopt.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index f166c31..918cf50 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -1925,6 +1925,10 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ || gimple_code (assign) != GIMPLE_ASSIGN) return false; + /* There cannot be any phi nodes in the middle bb. */ + if (!gimple_seq_empty_p (phi_nodes (middle_bb))) + return false; + lhs = gimple_assign_lhs (assign); ass_code = gimple_assign_rhs_code (assign); if (ass_code != MAX_EXPR && ass_code != MIN_EXPR) @@ -1938,6 +1942,10 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ || gimple_code (assign) != GIMPLE_ASSIGN) return false; + /* There cannot be any phi nodes in the alt middle bb. */ + if (!gimple_seq_empty_p (phi_nodes (alt_middle_bb))) + return false; + alt_lhs = gimple_assign_lhs (assign); if (ass_code != gimple_assign_rhs_code (assign)) return false; @@ -2049,6 +2057,10 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ || gimple_code (assign) != GIMPLE_ASSIGN) return false; + /* There cannot be any phi nodes in the middle bb. */ + if (!gimple_seq_empty_p (phi_nodes (middle_bb))) + return false; + lhs = gimple_assign_lhs (assign); ass_code = gimple_assign_rhs_code (assign); if (ass_code != MAX_EXPR && ass_code != MIN_EXPR) |