https://gcc.gnu.org/g:8b7b9d5a0a0e4c749b40ab67ab219649625971a8
commit r16-7018-g8b7b9d5a0a0e4c749b40ab67ab219649625971a8 Author: Andrew Pinski <[email protected]> Date: Fri Jan 23 23:13:25 2026 -0800 SLSR: Wrong type sometimes for rhs2 with pointers [PR123803] I messed up one of the new gimple_convert when there is still a pointer type (with -fwrapv-pointer or -fno-strict-overflow). The newrhs2 should be converted into sizetype instead of the type of the lhs. Other places were already done correctly, it was just in replace_rhs_if_not_dup which was broken this way. Pushed as obvious after bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/123803 gcc/ChangeLog: * gimple-ssa-strength-reduction.cc (replace_rhs_if_not_dup): For pointer lhs use sizetype. gcc/testsuite/ChangeLog: * gcc.dg/pr123803-1.c: New test. Signed-off-by: Andrew Pinski <[email protected]> Diff: --- gcc/gimple-ssa-strength-reduction.cc | 5 ++++- gcc/testsuite/gcc.dg/pr123803-1.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-ssa-strength-reduction.cc b/gcc/gimple-ssa-strength-reduction.cc index d493dc87d3a5..f3571e10e90d 100644 --- a/gcc/gimple-ssa-strength-reduction.cc +++ b/gcc/gimple-ssa-strength-reduction.cc @@ -3711,12 +3711,15 @@ replace_rhs_if_not_dup (enum tree_code new_code, tree new_rhs1, tree new_rhs2, { tree lhs = gimple_assign_lhs (c->cand_stmt); gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + tree rhs2_type = TREE_TYPE (lhs); + if (POINTER_TYPE_P (rhs2_type)) + rhs2_type = sizetype; new_rhs1 = gimple_convert (&gsi, true, GSI_SAME_STMT, UNKNOWN_LOCATION, TREE_TYPE (lhs), new_rhs1); new_rhs2 = gimple_convert (&gsi, true, GSI_SAME_STMT, UNKNOWN_LOCATION, - TREE_TYPE (lhs), new_rhs2); + rhs2_type, new_rhs2); slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, new_code, new_rhs1, new_rhs2); update_stmt (gsi_stmt (gsi)); diff --git a/gcc/testsuite/gcc.dg/pr123803-1.c b/gcc/testsuite/gcc.dg/pr123803-1.c new file mode 100644 index 000000000000..81c2356f721e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr123803-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-strict-overflow" } */ +/* PR tree-optimization/123803 */ + +/* SLSR with wrapping pointers converted the new + nhs2 into the pointer type instead of sizetype. */ +int f(int *x1,__SIZE_TYPE__ n) { + return *(x1 + n) + + *(x1 + 3 * n); +}
