Skip to content

Commit

Permalink
rtl-optimization/113255 - avoid re-associating REG_POINTER MINUS
Browse files Browse the repository at this point in the history
The following avoids re-associating

 (minus:DI (reg/f:DI 119)
    (minus:DI (reg/f:DI 120)
        (reg/f:DI 114)))

into

 (minus:DI (plus:DI (reg/f:DI 114)
        (reg/f:DI 119))
    (reg/f:DI 120))

as that possibly confuses the REG_POINTER heuristics of RTL
alias analysis.  This happens to miscompile the PRs testcase
during DSE which expands addresses via CSELIB which eventually
simplifies what it substituted to.  The original code does
the innocent ptr - (ptr2 - ptr2'), bias a pointer by the
difference of two other pointers.
  • Loading branch information
rguenth authored and ouuleilei-bot committed Feb 1, 2024
1 parent 8a84a1c commit f09c589
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gcc/simplify-rtx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3233,11 +3233,15 @@ simplify_context::simplify_binary_operation_1 (rtx_code code,
canonicalize (minus A (plus B C)) to (minus (minus A B) C).
Don't use the associative law for floating point.
The inaccuracy makes it nonassociative,
and subtle programs can break if operations are associated. */
and subtle programs can break if operations are associated.
Don't use the associative law when subtracting a MINUS from
a REG_POINTER as that can trick find_base_term into discovering
the wrong base. */

if (INTEGRAL_MODE_P (mode)
&& (plus_minus_operand_p (op0)
|| plus_minus_operand_p (op1))
|| ((!REG_P (op0) || !REG_POINTER (op0))
&& plus_minus_operand_p (op1)))
&& (tem = simplify_plus_minus (code, mode, op0, op1)) != 0)
return tem;

Expand Down

0 comments on commit f09c589

Please sign in to comment.