This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Combiner fixes

While testing a different ARM patch, I found that I was getting some
code changes that I couldn't explain.  It turned out to be a bug in the
combiner: a CONST_INT is created without using trunc_int_for_mode,
missing a sign extension, and it ends up not matching const_int_operand
for that reason.

While I was there, I also added some extra canonicalization that helps
on ARM (and produces the optimization I was previously only seeing by
accident).  According to the documentation,

   * In combinations of `neg', `mult', `plus', and `minus', the `neg'
     operations (if any) will be moved inside the operations as far as
     possible.  For instance, `(neg (mult A B))' is canonicalized as
     `(mult (neg A) B)', but `(plus (mult (neg A) B) C)' is
     canonicalized as `(minus A (mult B C))'.

It doesn't say so explicitly, but I take this to mean we can and should
change both

(set (reg/v:SI 137 [ q ])
     (plus:SI (mult:SI (neg:SI (reg/v:SI 135 [ y ])) (const_int 2))
              (reg/v:SI 137 [ q ])))


(set (reg/v:SI 137 [ q ])
     (plus:SI (mult:SI (reg/v:SI 135 [ y ]) (const_int -2))
              (reg/v:SI 137 [ q ])))


(set (reg/v:SI 137 [ q ])
     (minus:SI (reg/v:SI 137 [ q ])
        (mult:SI (reg/v:SI 135 [ y ]) (const_int 2))))

The latter is recognized by the ARM backend.  IMO the canonicalization
of a shift into a mult is supposed to produce multiplications by powers
of two, and those are all positive values.

On ARM, this helps as follow:
-       rsb     r3, r0, r0, lsl #30
-       add     r6, r6, r3, lsl #2
+       sub     r6, r6, r0, lsl #2

I've also added code to transform (mult (neg (...)) (const)) into
multiplication by the negated constant.

Bootstrapped and tested on i686-linux.  There are some ARM-specific bits
in here, since we forgot to mask off unwanted bits in a HOST_WIDE_INT in
some places.  ARM tests are in progress.   Ok?


Attachment: compoundop.diff
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]