Skip to content

Commit fbcbbfe

Browse files
rguenthRichard Biener
authored andcommitted
tree-optimization/118717 - store commoning vs. abnormals
When we sink common stores in cselim or the sink pass we have to make sure to not introduce overlapping lifetimes for abnormals used in the ref. The easiest is to avoid sinking stmts which reference abnormals at all which is what the following does. PR tree-optimization/118717 * tree-ssa-phiopt.cc (cond_if_else_store_replacement_1): Do not common stores referencing abnormal SSA names. * tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise. * gcc.dg/torture/pr118717.c: New testcase.
1 parent 75ab30f commit fbcbbfe

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* { dg-do compile } */
2+
3+
void jj(void);
4+
int ff1(void) __attribute__((__returns_twice__));
5+
struct s2 {
6+
int prev;
7+
};
8+
typedef struct s1 {
9+
unsigned interrupt_flag;
10+
unsigned interrupt_mask;
11+
int tag;
12+
int state;
13+
}s1;
14+
int ff(void);
15+
static inline
16+
int mm(s1 *ec) {
17+
if (ff())
18+
if (ec->interrupt_flag & ~(ec)->interrupt_mask)
19+
return 0;
20+
}
21+
void ll(s1 *ec) {
22+
int t = 1;
23+
int state;
24+
if (t)
25+
{
26+
{
27+
s1 *const _ec = ec;
28+
struct s2 _tag = {0};
29+
if (ff1())
30+
state = ec->state;
31+
else
32+
state = 0;
33+
if (!state)
34+
mm (ec);
35+
_ec->tag = _tag.prev;
36+
}
37+
if (state)
38+
__builtin_exit(0);
39+
}
40+
jj();
41+
}

gcc/tree-ssa-phiopt.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3646,7 +3646,9 @@ cond_if_else_store_replacement_1 (basic_block then_bb, basic_block else_bb,
36463646
|| else_assign == NULL
36473647
|| !gimple_assign_single_p (else_assign)
36483648
|| gimple_clobber_p (else_assign)
3649-
|| gimple_has_volatile_ops (else_assign))
3649+
|| gimple_has_volatile_ops (else_assign)
3650+
|| stmt_references_abnormal_ssa_name (then_assign)
3651+
|| stmt_references_abnormal_ssa_name (else_assign))
36503652
return false;
36513653

36523654
lhs = gimple_assign_lhs (then_assign);

gcc/tree-ssa-sink.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
3636
#include "cfgloop.h"
3737
#include "tree-eh.h"
3838
#include "tree-ssa-live.h"
39+
#include "tree-dfa.h"
3940

4041
/* TODO:
4142
1. Sinking store only using scalar promotion (IE without moving the RHS):
@@ -516,7 +517,8 @@ sink_common_stores_to_bb (basic_block bb)
516517
gimple *def = SSA_NAME_DEF_STMT (arg);
517518
if (! is_gimple_assign (def)
518519
|| stmt_can_throw_internal (cfun, def)
519-
|| (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL))
520+
|| (gimple_phi_arg_edge (phi, i)->flags & EDGE_ABNORMAL)
521+
|| stmt_references_abnormal_ssa_name (def))
520522
{
521523
/* ??? We could handle some cascading with the def being
522524
another PHI. We'd have to insert multiple PHIs for

0 commit comments

Comments
 (0)