https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66489
Bug ID: 66489 Summary: combine fails to merge insns if some are reused later on Product: gcc Version: 6.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ktkachov at gcc dot gnu.org Target Milestone: --- Consider code: int f2(int a, int b, int c, int d) { a = -a; b += a * c; c += a * d; return b ^ c; } On aarch64 this could be written with to msub instructions, RTL code: (set (reg/i:SI 0 x0) (minus:SI (reg:SI 1 x1 [ b ]) (mult:SI (reg:SI 0 x0 [ a ]) (reg:SI 2 x2 [ c ])))) However, combine doesn't merge the neg and the multiply-adds and generates: f2: neg w4, w0 madd w0, w4, w2, w1 madd w3, w4, w3, w2 eor w0, w0, w3 ret If we modify the code to only do a single multiply-accumulate: int f2(int a, int b, int c, int d) { a = -a; b += a * c; return b; } Then they the expected single msub instruction is generated. I think this is due to combine being scared of the negated 'a' being used in two places.