[Bug c/113106] Missing CSE with cast to volatile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106 --- Comment #5 from Uroš Bizjak --- The issue in comment #2 happens in a couple of places when compiling linux kernel (with named address spaces enabled). However, the issue is not specific to named AS, I was just more attentive to moves from %gs: prefixed locations.
[Bug c/113106] Missing CSE with cast to volatile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106 --- Comment #4 from Uroš Bizjak --- (In reply to Richard Biener from comment #3) > The situation with address-spaces isn't valid as we need to preserve the > second load because it's volatile. I think we simply refuse to combine > volatile loads out of caution in the first case. int __seg_gs b; return *(volatile __seg_gs int *) + b; But the above is the same w.r.t to volatile as: int a; return *(volatile int *) + a; ? BTW: I also checked with clang, and it creates expected code in all cases.
[Bug c/113106] Missing CSE with cast to volatile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106 Richard Biener changed: What|Removed |Added CC||rguenth at gcc dot gnu.org --- Comment #3 from Richard Biener --- The situation with address-spaces isn't valid as we need to preserve the second load because it's volatile. I think we simply refuse to combine volatile loads out of caution in the first case.
[Bug c/113106] Missing CSE with cast to volatile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106 --- Comment #2 from Uroš Bizjak --- For reference, the same optimization should be applied with address spaces: --cut here-- int __seg_gs b; int bar(void) { return *(volatile __seg_gs int *) + b; } --cut here-- the above testcase currently compiles to: movl%gs:b(%rip), %eax addl%gs:b(%rip), %eax ret but can be compiled to: movl%gs:b(%rip), %eax addl%eax, %eax ret
[Bug c/113106] Missing CSE with cast to volatile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106 --- Comment #1 from Uroš Bizjak --- Perhaps related, --cut here-- int a; int foo(void) { return *(volatile int *) + *(volatile int *) } --cut here-- compiles with -O2 to: movla(%rip), %eax movla(%rip), %edx addl%edx, %eax ret but may be compiled to: movla(%rip), %eax addla(%rip), %eax ret (the memory read may propagate to the insn)