tree-optimization/100810 - avoid undefs in IVOPT rewrites
authorRichard Biener <rguenther@suse.de>
Fri, 1 Apr 2022 09:30:00 +0000 (11:30 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 25 Apr 2022 07:25:33 +0000 (09:25 +0200)
commitab91c10792cd3a1ba1495aa30a34ca17b043bafb
tree20282594335b34cce5bcc453665bd344695bbd39
parentb6e22db8564827c82108e0b7fa1a84675379c12b
tree-optimization/100810 - avoid undefs in IVOPT rewrites

The following attempts to avoid IVOPTs rewriting uses using
IV candidates that involve undefined behavior by using uninitialized
SSA names.  First we restrict the set of candidates we produce
for such IVs to the original ones and mark them as not important.
Second we try to only allow expressing uses with such IV if they
originally use them.  That is to avoid rewriting all such uses
in terms of other IVs.  Since cand->iv and use->iv seem to never
exactly match up we resort to comparing the IV bases.

The approach ends up similar to the one posted by Roger at
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/578441.html
but it marks IV candidates rather than use groups and the cases
we allow in determine_group_iv_cost_generic are slightly different.

2022-01-04  Richard Biener  <rguenther@suse.de>

PR tree-optimization/100810
* tree-ssa-loop-ivopts.cc (struct iv_cand): Add involves_undefs flag.
(find_ssa_undef): New function.
(add_candidate_1): Avoid adding derived candidates with
undefined SSA names and mark the original ones.
(determine_group_iv_cost_generic): Reject rewriting
uses with a different IV when that involves undefined SSA names.

* gcc.dg/torture/pr100810.c: New testcase.
* gcc.dg/torture/pr105337.c: Likewise.
gcc/testsuite/gcc.dg/torture/pr100810.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr105337.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.cc