https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109393
--- Comment #7 from Manolis Tsamis <manolis.tsamis at vrull dot eu> --- After some attempts to improve on this, my current solution is: 1) Do not change pointer_int_sum in c-common (otherwise codegen regressions are observed) 2) Introduce a pattern that folds (unsigned type) (x + CONST_INT_1) * CONST_INT_2 to (unsigned type) (x * CONST_INT_2) + (unsigned type) (CONST_INT_1 * CONST_INT_1) under the right circumstances. This combination improves codegen (including the testcase provided) and also doesn't cause any regressions on the GCC testsuite or benchmarks that I have tried so far. Given that a[(ulong) i +- C] in GIMPLE is quite common, I believe this change helps with folding / canonicalization in many cases. My current match.pd pattern to do that is below; any feedback or improvements are welcome. (simplify (mult (convert@3 (plus @0 INTEGER_CST@1)) INTEGER_CST@2) (with { tree tt = TREE_TYPE(@3); } (if (INTEGRAL_TYPE_P (type) && !TYPE_SATURATING (type) && !TYPE_OVERFLOW_TRAPS (type) && !TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))) (plus (mult (convert:tt @0) @2) (mult (convert:tt @1) @2)))))