[Bug target/55987] Redundant constant emitted

2013-02-15 Thread til...@code-monkey.de


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



--- Comment #2 from Tilman Sauerbeck  2013-02-15 
16:50:52 UTC ---

Created attachment 29470

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29470

dejagnu testcase



Simplified dejagnu test case.


[Bug target/56110] Sub-optimal code: unnecessary CMP after AND

2013-02-16 Thread til...@code-monkey.de


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



--- Comment #1 from Tilman Sauerbeck  2013-02-16 
16:49:34 UTC ---

Changing the literal in the test function so that it fits in 8 bits makes gcc

go with the TST instruction instead of AND+CMP:



unsigned f2 (unsigned x, unsigned m)

{

if (m & 0x80)

x >>= 8;



return x;

}



=>

tstr1, #128

movner0, r0, lsr #8

bxlr



So I guess I shouldn't ask why gcc generates AND+CMP instead of ANDS, but why

it chooses not to use TST.


[Bug target/56110] Sub-optimal code: unnecessary CMP after AND

2013-03-16 Thread til...@code-monkey.de


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



--- Comment #2 from Tilman Sauerbeck  2013-03-16 
09:01:17 UTC ---

Created attachment 29677

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29677

WIP patch



I'm not really sure if this patch is good or bad. The discussion on the ML died

off eventually (maybe because I asked one too many silly questions).



Anyway, without guidance I won't be able to finish this, but I want to post my

WIP here at least.


[Bug target/59689] New: Code bloat introduced by pointer arithmetic

2014-01-05 Thread til...@code-monkey.de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59689

Bug ID: 59689
   Summary: Code bloat introduced by pointer arithmetic
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: til...@code-monkey.de

The C snippet below contains two lines which AFAICS should be equivalent, but
depending on which of the two is used, gcc will either generate "good" (few
instructions) or "bad" (more instructions) code.

$ armv5tel-softfloat-linux-gnueabi-gcc -O2 t.c -S -DGOOD -o good.S -std=gnu99
$ armv5tel-softfloat-linux-gnueabi-gcc -O2 t.c -S -DBAD -o bad.S -std=gnu99
$ wc -l good.S bad.S 
 132 good.S
 206 bad.S
$

#define M(c) \
do { \
c = *(++ptr); \
if (!flag && f2()) \
flag = 1; \
if (!flag) { \
f3 (c); \
} \
} while (0)

unsigned f2 (void);
void f3 (unsigned c);

void f()
{
const int size = 512;
char *ptr, line[size];
unsigned flag = 0;

#ifdef GOOD
ptr = &line[0] - 1; // !!
#elif BAD
ptr = line; ptr--;  // !!
#else
# error need either GOOD or BAD
#endif

for (;;) {
unsigned c;

M (c); M (c); M (c); M (c);
M (c); M (c); M (c); M (c);

M (c); M (c); M (c); M (c);
M (c); M (c); M (c); M (c);
}
}


[Bug target/59689] Code bloat introduced by pointer arithmetic

2014-01-05 Thread til...@code-monkey.de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59689

--- Comment #2 from Tilman Sauerbeck  ---
Sigh, I wondered about that but wasn't sure. Sorry about the noise.


[Bug pending/55987] New: Redundant constant emitted

2013-01-14 Thread til...@code-monkey.de


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



 Bug #: 55987

   Summary: Redundant constant emitted

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: pending

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: til...@code-monkey.de

Target: arm





For this code



  uint32_t add (uint32_t x, uint32_t y)

  {

  uint32_t a, b;



  a = (x & 0x7f7f7f7f) + (y & 0x7f7f7f7f);

  b = (x ^ y) & ~0x7f7f7f7f;



  return a ^ b;

  }



gcc 4.7.2 generates the following machine code for ARMv5:



$ gcc -Wall -O2 -mtune=arm9tdmi -march=armv5te -S add.c



ldrr2, .L2 @ .word  2139062143

ldrr3, .L2+4   @ .word -2139062144

eorip, r1, r0

andr1, r1, r2

andr2, r0, r2

andr3, ip, r3

addr0, r1, r2

eorr0, r3, r0

bxlr



gcc missed that we can use bic to clear the low bits, which means

we don't need that 2nd constant:



ldrr2, .L2 @ .word 2139062143

eorip, r1, r0

bicip, ip, r2  @ use bic instead of and

andr1, r1, r2

andr0, r0, r2

addr0, r0, r1

eorr0, r0, ip

bxlr


[Bug target/56096] New: Bad code generated for conditional shift

2013-01-23 Thread til...@code-monkey.de


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



 Bug #: 56096

   Summary: Bad code generated for conditional shift

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: target

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: til...@code-monkey.de





Compiling this snippet



unsigned f1 (unsigned x, unsigned m)

{

x >>= ((m & 0x008080) ? 8 : 0);

return x;

}



with gcc 4.7.2 gives this code for ARMv5:



$ armv5tel-softfloat-linux-gnueabi-gcc -O2 -S -o- f.c

[...]

ldrr3, .L4

andr3, r1, r3

cmpr3, #0

movner3, #8   @ XXX

moveqr3, #0   @ XXX

movr0, r0, lsr r3   @ XXX

bxlr

[...]



Those three mov instructions are clearly sub-optimal.



Replacing the ternary operator with an if-statement gives the expected code

sequence:



unsigned f1 (unsigned x, unsigned m)

{

if (m & 0x008080)

x >>= 8;



return x;

}



-> 

ldrr3, .L6

andr3, r1, r3

cmpr3, #0

movner0, r0, lsr #8

bxlr



ie we saved two mov instructions.


[Bug target/56110] New: Sub-optimal code: unnecessary CMP after AND

2013-01-25 Thread til...@code-monkey.de


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



 Bug #: 56110

   Summary: Sub-optimal code: unnecessary CMP after AND

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: target

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: til...@code-monkey.de

Target: arm





Compiling this code



unsigned f1 (unsigned x, unsigned m)

{

if (m & 0x008080)

x >>= 8;



return x;

}



with gcc 4.7.2 gives this code for ARMv5:



$ armv5tel-softfloat-linux-gnueabi-gcc -O2 -S -o- f1.c

[...]

ldrr3, .L6

andr3, r1, r3   @ XXX

cmpr3, #0   @ XXX

movner0, r0, lsr #8

bxlr

[...]



AFAICS we could get rid of the CMP if we used ANDS instead of AND:



ldrr3, .L6

andsr3, r1, r3

movner0, r0, lsr #8

bxlr