aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-phiopt.cc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-07-14 15:55:34 -0700
committerAndrew Pinski <apinski@marvell.com>2023-07-19 09:18:50 -0700
commit8c79b49cd4fa742f7be739dd21fd2aa040cc1ba3 (patch)
tree2c2109e96426b9b9b7bffeca43a72f806ad22b68 /gcc/tree-ssa-phiopt.cc
parenta86d5eca6a11c25da4aff436f53589950641675f (diff)
downloadgcc-8c79b49cd4fa742f7be739dd21fd2aa040cc1ba3.zip
gcc-8c79b49cd4fa742f7be739dd21fd2aa040cc1ba3.tar.gz
gcc-8c79b49cd4fa742f7be739dd21fd2aa040cc1ba3.tar.bz2
[PATCH] Fix tree-opt/110252: wrong code due to phiopt using flow sensitive info during match
Match will query ranger via tree_nonzero_bits/get_nonzero_bits for 2 and 3rd operand of the COND_EXPR and phiopt tries to do create the COND_EXPR even if we moving one statement. That one statement could have some flow sensitive information on it based on the condition that is for the COND_EXPR but that might create wrong code if the statement was moved out. This is similar to the previous version of the patch except now we use flow_sensitive_info_storage instead of manually doing the save/restore and also handle all defs on a gimple statement rather than just for lhs of the gimple statement. Oh and a few more testcases were added that was failing before. OK? Bootsrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/110252 gcc/ChangeLog: * tree-ssa-phiopt.cc (class auto_flow_sensitive): New class. (auto_flow_sensitive::auto_flow_sensitive): New constructor. (auto_flow_sensitive::~auto_flow_sensitive): New deconstructor. (match_simplify_replacement): Temporarily remove the flow sensitive info on the two statements that might be moved. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-25b.c: Updated as __builtin_parity loses the nonzerobits info. * gcc.c-torture/execute/pr110252-1.c: New test. * gcc.c-torture/execute/pr110252-2.c: New test. * gcc.c-torture/execute/pr110252-3.c: New test. * gcc.c-torture/execute/pr110252-4.c: New test.
Diffstat (limited to 'gcc/tree-ssa-phiopt.cc')
-rw-r--r--gcc/tree-ssa-phiopt.cc51
1 files changed, 48 insertions, 3 deletions
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 467c9fd..9d542fd 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -708,6 +708,45 @@ move_stmt (gimple *stmt, gimple_stmt_iterator *gsi, auto_bitmap &inserted_exprs)
reset_flow_sensitive_info (name);
}
+/* RAII style class to temporarily remove flow sensitive
+ from ssa names defined by a gimple statement. */
+class auto_flow_sensitive
+{
+public:
+ auto_flow_sensitive (gimple *s);
+ ~auto_flow_sensitive ();
+private:
+ auto_vec<std::pair<tree, flow_sensitive_info_storage>, 2> stack;
+};
+
+/* Constructor for auto_flow_sensitive. Saves
+ off the ssa names' flow sensitive information
+ that was defined by gimple statement S and
+ resets it to be non-flow based ones. */
+
+auto_flow_sensitive::auto_flow_sensitive (gimple *s)
+{
+ if (!s)
+ return;
+ ssa_op_iter it;
+ tree def;
+ FOR_EACH_SSA_TREE_OPERAND (def, s, it, SSA_OP_DEF)
+ {
+ flow_sensitive_info_storage storage;
+ storage.save_and_clear (def);
+ stack.safe_push (std::make_pair (def, storage));
+ }
+}
+
+/* Deconstructor, restores the flow sensitive information
+ for the SSA names that had been saved off. */
+
+auto_flow_sensitive::~auto_flow_sensitive ()
+{
+ for (auto p : stack)
+ p.second.restore (p.first);
+}
+
/* The function match_simplify_replacement does the main work of doing the
replacement using match and simplify. Return true if the replacement is done.
Otherwise return false.
@@ -793,9 +832,15 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb,
return false;
tree type = TREE_TYPE (gimple_phi_result (phi));
- result = gimple_simplify_phiopt (early_p, type, stmt,
- arg_true, arg_false,
- &seq);
+ {
+ auto_flow_sensitive s1(stmt_to_move);
+ auto_flow_sensitive s_alt(stmt_to_move_alt);
+
+ result = gimple_simplify_phiopt (early_p, type, stmt,
+ arg_true, arg_false,
+ &seq);
+ }
+
if (!result)
return false;