[Bug c/108298] Wrong optimization of volatile access from gcc 11 and beyond
segher at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 5 17:10:05 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108298
--- Comment #5 from Segher Boessenkool <segher at gcc dot gnu.org> ---
This is not x86-specific. Like on powerpc64 we get
addi 3,3,3 # 11 [c=4 l=4] *addsi3/1
extsw 3,3 # 17 [c=4 l=4] extendsidi2/1
blr # 25 [c=4 l=4] simple_return
Before RTL all is fine still:
int foo (int a, int b, int c)
{
int _1;
int _2;
;; basic block 2, loop depth 0
;; pred: ENTRY
_1 = a_3(D) + 1;
b = _1;
_2 ={v} MEM[(volatile int *)&b];
a_6 = _2 + 2;
return a_6;
;; succ: EXIT
}
But it is expanded to something that is not going through memory:
;; _2 ={v} MEM[(volatile int *)&b];
(insn 10 9 0 (set (reg:SI 118 [ _2 ])
(subreg/s/u:SI (reg/v:DI 121 [ b+-4 ]) 4)) "108298.c":10:9 -1
(nil))
More information about the Gcc-bugs
mailing list