https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116514
Bug ID: 116514
Summary: known pointer alignment is not used for constant
propagation
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mkretz at gcc dot gnu.org
Target Milestone: ---
Test case (https://compiler-explorer.com/z/Gxd9KaG1T):
int
test(int* a, int* b)
{
auto delta = (int*)__builtin_assume_aligned(b, 32)
- (int*)__builtin_assume_aligned(a, 32);
auto x = delta % 8;
return (x == 0);
}
The expression 'delta % 8' should be optimized to a 0 constant. Consequently 'x
== 0' must satisfy __builtin_constant_p and be true. This could then be used to
completely avoid emitting code for a SIMD epilogue for given a range.
Clang manages to fold the above function to a constant 1.