https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104498
Bug ID: 104498 Summary: Alias attribute being ignored by scheduler Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: avieira at gcc dot gnu.org Target Milestone: --- Whilst working on a tuning structure I saw a correctness regression that I believe is a result of the alias attribute not working properly. You can reproduce it using an existing tuning for AArch64 using: gcc -O2 src/gcc/gcc/testsuite/gcc.c-torture/execute/alias-2.c -S -mtune=cortex-a34 This will lead to the 'a[off] = 2' store being moved after the b load in 'b[off] != 2'. In RTL: (insn 23 18 19 2 (set (reg:SI 110 [ b[off.0_1] ]) (mem:SI (plus:DI (mult:DI (reg:DI 99 [ off.0_1 ]) (const_int 4 [0x4])) (reg/f:DI 97)) [1 b[off.0_1]+0 S4 A32])) "gcc/gcc/testsuite/gcc.c-torture/execute/alias-2.c":10:6 52 {*movsi_aarch64} (expr_list:REG_DEAD (reg:DI 99 [ off.0_1 ]) (expr_list:REG_DEAD (reg/f:DI 97) (nil)))) (insn 19 23 24 2 (set (mem:SI (plus:DI (mult:DI (reg:DI 99 [ off.0_1 ]) (const_int 4 [0x4])) (reg/f:DI 104)) [1 a[off.0_1]+0 S4 A32]) (reg:SI 106)) "gcc/gcc/testsuite/gcc.c-torture/execute/alias-2.c":9:9 52 {*movsi_aarch64} (expr_list:REG_DEAD (reg:SI 106) (expr_list:REG_DEAD (reg/f:DI 104) (nil)))) After some debugging I found that true_dependence returns false for these two memory accesses because base_alias_check sees they have different base objects ('a' and 'b') and deduces they can't alias based on that, without realising 'b' isn't an actual base object but an alias to 'a'. I think we should make it so that at expand pointers to 'b' get 'a' as a base object.