https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119084
Bug ID: 119084 Summary: LoongArch: __builtin_lsx_vldx can be incorrectly reordered Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: xry111 at gcc dot gnu.org Target Milestone: --- typedef signed char V16QI __attribute__ ((vector_size (16))); static char x[128]; __attribute__ ((noipa)) int noopt (int x) { return x; } int main (void) { int t = noopt (32); x[32] = 1; #if 0 /* This can work around the issue */ asm("":::"memory"); #endif V16QI y = __builtin_lsx_vldx (x, t); if (y[0] != 1) __builtin_trap (); } produces: la.local $r12,.LANCHOR0 addi.w $r14,$r0,1 # 0x1 vldx $vr0,$r12,$r4 st.b $r14,$r12,32 vpickve2gr.b $r12,$vr0,0 addi.w $r13,$r0,1 # 0x1 bstrpick.w $r12,$r12,7,0 bne $r12,$r13,.L6 Note that st.b is incorrectly reordered after vldx. It's because (define_insn "lsx_vldx" [(set (match_operand:V16QI 0 "register_operand" "=f") (unspec:V16QI [(match_operand:DI 1 "register_operand" "r") (match_operand:DI 2 "reg_or_0_operand" "rJ")] UNSPEC_LSX_VLDX))] "ISA_HAS_LSX" { return "vldx\t%w0,%1,%z2"; } [(set_attr "type" "simd_load") (set_attr "mode" "V16QI")]) seems (to the compiler) not accessing the memory at all.