https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113106

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |rtl-optimization
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2023-12-21
             Status|UNCONFIRMED                 |NEW

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Uroš Bizjak from comment #4)
> (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 + b;
> 
> But the above is the same w.r.t to volatile as:
> 
> int a;
> return *(volatile int *) &a + a;
> 
> ?
> 
> BTW: I also checked with clang, and it creates expected code in all cases.

But you don't get

       movl    %gs:b(%rip), %eax
       addl    %eax, %eax

or

       movl    b(%rip), %eax
       addl    %eax, %eax

which I think would be wrong.  The volatile access doesn't need to yield
the same value as the non-volatile one so we can't value-number them the
same.

The combine issue remains of course.  But GCCs point was always that
trying to optimize volatile is wasted time.

Reply via email to