On 3/17/2026 5:54 AM, Richard Biener wrote:
This decouples the PRE reference IL from the VN hash tables, following
the corresponding PR103037 fix for nary expressions in r12-7389 to avoid
correctness issues regarding to access paths when inserting expressions.
Unfortunately this makes existing workarounds for alignment and alias
mismatches ineffective so those have to be re-implemented. Instead
of going back to implement canonexpr() during the ANTIC dataflow the
following does this at insertion time, hoping all relevant reaching
expressions will survive. A convenient place to do this is
sorted_array_from_bitmap_set, the actual magic worker is 'prefer',
for the moment handling alignment and innermost access size only,
as those are the cases we have test coverage. In particular the
access path difference seen in this PR is not covered - it is enough
to fix the AVAIL_OUT computation in compute_avail for this.
Where the old fixup code massaged the expressions the new code selects
from existing expressions or as fallback makes sure to not perform
code insertion when two incompatible expressions met.
Bootstrapped and tested on x86_64-unknown-linux-gnu. I've built a
set of applications looking for ICEs successfully, still I consider
this moderately risky at this point (but I'd also like to see
coverage rather than trying to hack the missing alias-set handling
in place without such coverage). I'll try to come up with a GIMPLE FE
testcase for this but it's also that the later we're putting this in
the worse (IMO), defering to stage1 and backporting will also not
really result in better coverage.
So what's your opinion?
OK for trunk?
Thanks,
Richard.
PR tree-optimization/122380
* tree-ssa-sscvn.h (copy_reference_ops_from_ref): Declare.
(vn_reference_compute_hash): Likewise.
(vn_reference_eq): Add parameter indicating lexical equivalence,
defaulted to false.
* tree-ssa-sccvn.cc (vn_reference_eq): Likewise.
(print_vn_reference_ops): Print alias type and alignment.
(vn_reference_compute_hash): Export.
(copy_reference_ops_from_ref): Likewise.
* tree-ssa-pre.cc (pre_expr_d::equal): Use lexical equivalence.
(get_or_alloc_expr_for_reference): Also get value-id, upon
zero assign a new value-id if the expression is unknown.
(expr_cmp): New helper.
(prefer): Likewise.
(pre_expr_DFS): Get expression exclusion bitmap and honor it.
(sorted_array_from_bitmap_set): If done for insertion, do limited
canonexpr() via pairwise prefer on expression pairs with the same
value, populating an exclution bitmap.
(phi_translate_1): Do not use the VN hashtable expressions
or insert there. Instead maintain a PRE view of expressions.
(clean): Adjust.
(do_hoist_insertion): Likewise.
(insert): Likewise.
(compute_avail): Use gimple_could_trap_p_1
on the original stmt rather than vn_reference_may_trap on
the VN leader. Use the original stmt operands for the PRE
view of reference expressions, only use the value number from the VN
tables. Remove no longer effective workarounds for semantically
different references with same value.
(fini_pre): Release operand vectors for PRE IL reference
expressions.
* g++.dg/torture/pr122380.C: New testcase.
* gcc.dg/torture/pr65270-3.c: Likewise.
* gcc.dg/tree-ssa/ssa-pre-30.c: XFAIL.
Ouch at this point. In isolation I'd lean towards deferral due to
complexity of the fix, but you're obviously in the best position to
judge the technical pro/cons. So I'd go with your recommendation.
Jeff