[Bug tree-optimization/105142] [12 Regression] Wrong code with -O2 since r12-2591
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Apr 6 06:15:06 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105142
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:fc8d9e4497032dd295aac9414042163f92250b77
commit r12-8012-gfc8d9e4497032dd295aac9414042163f92250b77
Author: Richard Biener <rguenther@suse.de>
Date: Mon Apr 4 12:23:28 2022 +0200
tree-optimization/105142 - wrong code with maybe_fold_{and,or}_comparisons
The following avoids expanding definitions in regions conditionally
executed under the condition A when simplifying A && B or A || B.
This is done by passing down the basic-block of the outer condition
to maybe_fold_{and,or}_comparisons, through the various helpers
in gimple-fold.cc that might call back to maybe_fold_{and,or}_comparisons
and ultimatively to maybe_fold_comparisons_from_match_pd where the
fix is to provide a custom valueization hook to
gimple_match_op::resimplify that avoids looking at definitions
that do not dominate the outer block.
For the testcase this avoids combining a stmt that invokes undefined
integer overflow when the outer condition is false but it also
aovids combining stmts with range information that is derived from
the outer condition.
The new parameter to maybe_fold_{and,or}_comparisons is defaulted
to nullptr and I only adjusted the if-combine to pass down the
outer block. I think other callers like tree-if-conv have the
same issue but it's not straight-forward as to what to do there.
2022-04-05 Richard Biener <rguenther@suse.de>
PR tree-optimization/105142
* gimple-fold.h (maybe_fold_and_comparisons): Add defaulted
basic-block parameter.
(maybe_fold_or_comparisons): Likewise.
* gimple-fold.cc (follow_outer_ssa_edges): New.
(maybe_fold_comparisons_from_match_pd): Use follow_outer_ssa_edges
when an outer condition basic-block is specified.
(and_comparisons_1, and_var_with_comparison,
and_var_with_comparison_1, or_comparisons_1,
or_var_with_comparison, or_var_with_comparison_1): Receive and pass
down the outer condition basic-block.
* tree-ssa-ifcombine.cc (ifcombine_ifandif): Pass down the
basic-block of the outer condition.
* g++.dg/torture/pr105142.C: New testcase.
More information about the Gcc-bugs
mailing list