The attached testcase shows a code generation regression which can be seen on 
x86 but I believe it to be target indepedent.

The code is copying data between two structures, both of which contain 
bitfields. The source structure uses 1-bit bitfields of type "int", while the 
destination structure uses 1-bit bitfields of type "_Bool". At the end of the 
tree optimizers, the code looks like this:

    params.cliplmt_ch1 = (int) msg.cliplmt_ch1 != 0;
    params.cliplmt_ch2 = (int) msg.cliplmt_ch2 != 0;
    params.gate_ch1 = (int) msg.gate_ch1 != 0;
    params.gate_ch2 = (int) msg.gate_ch2 != 0;

The problem is that the comparison with zero is never removed by the 
optimizers. The generated code looks like this:

        testb   $1, %bl
        setne   %cl

In 3.4, instead, the generated code looks better:

        andl    $1, %ebx



Notice this this does not happen in C++ (using a "bool" bitfield instead 
of "_Bool"). We get a BITFIELD_REF there:

    D.1643 = BIT_FIELD_REF <msg, 8, 40>;
    params.cliplmt_ch1 = (D.1643 & 1) != 0;
    params.cliplmt_ch2 = (D.1643 & 2) != 0;
    params.gate_ch1 = (D.1643 & 4) != 0;
    params.gate_ch2 = (D.1643 & 8) != 0;

and the generated code is optimal.

-- 
           Summary: [4.0 Regression] Inefficient code generated for bitfield
                    assignment
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: giovannibajo at libero dot it
                CC: aleph at develer dot com,bernie at develer dot com,gcc-
                    bugs at gcc dot gnu dot org,sayle at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19331

Reply via email to