https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68590
--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Eric Botcazou from comment #10) > > So the original compliant was that if we do that we pessimize code-gen > > because we un-CSE a possibly large sub-expression. > > Then maybe the "possibly large sub-expression" should be taken into account. > We already try by means of skip_simple_arithmetic, but it's too simple. > > > So you say that any tree-shared expr is only expanded once (as if it were > > wrapped in a save-expr)? > > No, it will be reexpanded if it has no TREE_SIDE_EFFECTS. What I'm saying > is that you control it by means of TREE_SIDE_EFFECTS. > > > Oh, so fold is performing CSE here? Shouldn't _that_ folding not set > > TREE_SIDE_EFFECTS on the SAVE_EXPR? Instead of forcing it on every user... > > It's not just fold, it's the way SAVE_EXPR works in GENERIC. You need to be > able to control when the variable is initialized at run time, otherwise it's > a recipe for disaster. Btw, removing TREE_SIDE_EFFECTS passes bootstrap for all languages but causes (not double-checked whether they are really caused by the change but they are new to my eyes): === acats tests === FAIL: c64107a FAIL: cc3007b === g++ tests === FAIL: g++.dg/ext/vla9.C -std=gnu++11 execution test FAIL: g++.dg/ext/vla9.C -std=gnu++14 execution test FAIL: g++.dg/ext/vla9.C -std=gnu++98 execution test FAIL: g++.dg/pr58950.C -std=gnu++11 (test for warnings, line 6) FAIL: g++.dg/pr58950.C -std=gnu++11 (test for excess errors) FAIL: g++.dg/pr58950.C -std=gnu++14 (test for warnings, line 6) FAIL: g++.dg/pr58950.C -std=gnu++14 (test for excess errors) FAIL: g++.dg/pr58950.C -std=gnu++98 (test for warnings, line 6) FAIL: g++.dg/pr58950.C -std=gnu++98 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O0 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O1 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O2 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O3 -g (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -Os (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O0 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O1 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O2 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O3 -g (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -Os (test for excess errors) === gcc tests === FAIL: gcc.dg/c99-bool-1.c execution test FAIL: c-c++-common/gomp/atomic-12.c (test for excess errors) FAIL: c-c++-common/gomp/atomic-13.c (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O0 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O1 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O2 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -O3 -g (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-3.c -Os (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O0 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O1 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O2 (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O2 -flto -fno-use-linker-plugin -flto-partition=none (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -O3 -g (test for excess errors) FAIL: c-c++-common/ubsan/save-expr-4.c -Os (test for excess errors)