Bug 41481 - missed optimization in cse
Summary: missed optimization in cse
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2009-09-27 09:13 UTC by Carrot
Modified: 2021-08-29 22:52 UTC (History)
2 users (show)

See Also:
Host: i686-linux
Target: arm-eabi
Build: i686-linux
Known to work:
Known to fail:
Last reconfirmed: 2009-10-06 07:20:28


Attachments
test case (94 bytes, text/plain)
2009-09-27 09:13 UTC, Carrot
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Carrot 2009-09-27 09:13:06 UTC
Compile following code with options -Os -march=armv5te -mthumb,

class A
{
 public:
  int ah;
  unsigned field : 2;
};

void foo(A* p)
{
  p->ah = 1;
  p->field = 1;
}

We can get:

        mov     r3, #1             // A
        str     r3, [r0]
        ldrb    r3, [r0, #4]
        mov     r2, #3
        bic     r3, r3, r2
        mov     r2, #1             // B
        orr     r3, r3, r2
        strb    r3, [r0, #4]
        @ sp needed for prologue
        bx      lr

Both instruction A and B load a constant 1 into register. We can load 1 into r1 in instruction A and use r1 when constant 1 is required. So instruction B can be removed.

cse pass doesn't find this opportunity is because it needs all expressions to be of the same mode. But in rtl level the first 1 is in mode SI and the second 1 is in mode QI. Arm doesn't has any physical register of QI mode, so all of them are put into 32 bit physical register and causes redundant load of constant 1.
Comment 1 Carrot 2009-09-27 09:13:28 UTC
Created attachment 18662 [details]
test case
Comment 2 Ramana Radhakrishnan 2009-10-06 07:20:28 UTC
confirmed - FYI, the problem doesn't arise with !-mthumb.