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

            Bug ID: 122343
           Summary: Propagate volatile memory operands
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

The following testcase:

--cut here--
volatile int m;

int foo (int z)
{
  z *= 123;
  return m + z;
}
--cut here--

currently compiles to (gcc -O2):

foo:
        imull   $123, %edi, %eax
        movl    m(%rip), %edx
        addl    %edx, %eax
        ret

The memory operand can propagate to ADDL instruction without affecting volatile
correctness. Now that we have late combine pass, perhaps it can be taught to
carefully do this optimization.

OTOH, clang compiles the testcase to the expected:

foo:
        imull   $123, %edi, %eax
        addl    m(%rip), %eax
        retq

This improvement would help to further optimize linux kernel.

Reply via email to