[Bug debug/41893] ICE with -combine and debug

2010-03-28 Thread kevin at koconnor dot net


--- Comment #4 from kevin at koconnor dot net  2010-03-28 14:43 ---
This problem has returned.  The test case above no longer causes the problem -
but simply changing the test case to also assign a value to the variable shows
the problem.  This is with gcc from svn (r157452).

New test case:


cat > file1.c << EOF
struct s1_s {
int v;
};
struct s1_s g1;
void __attribute__((externally_visible)) func1() {
struct s1_s *l1 = &g1;
l1->v = 0;
}
EOF

cat > file2.c << EOF
extern struct s1_s g1;
void func2() {
&g1;
}
EOF

cc -O -g -fwhole-program -combine -c file1.c file2.c



-- 


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



[Bug c/43557] New: ICE with -combine and -g

2010-03-28 Thread kevin at koconnor dot net
The following causes an ICE with latest gcc 4.5.0 (svn r157452):


cat > file1.c << EOF
struct s1_s {
int v;
};
struct s1_s g1;
void __attribute__((externally_visible)) func1() {
struct s1_s *l1 = &g1;
l1->v = 0;
}
EOF

cat > file2.c << EOF
extern struct s1_s g1;
void func2() {
&g1;
}
EOF

cc -O -g -fwhole-program -combine -c file1.c file2.c


This appears similar to pr41893.


$ ~/src/gcc/install/bin/gcc -O -g -fwhole-program -combine -c file1.c file2.c
file1.c: In function ‘func1’:
file1.c:5:42: internal compiler error: in simplify_subreg, at
simplify-rtx.c:5139
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

$ ~/src/gcc/install/bin/gcc --version
gcc (GCC) 4.5.0 20100315 (experimental)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


-- 
   Summary: ICE with -combine and -g
   Product: gcc
   Version: 4.5.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kevin at koconnor dot net


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



[Bug debug/43557] ICE with -combine and -g

2010-04-03 Thread kevin at koconnor dot net


--- Comment #6 from kevin at koconnor dot net  2010-04-04 03:50 ---
I've confirmed this fix (r157942) works (both for the test case and for the
underlying program - SeaBIOS).  SeaBIOS ( http://seabios.org/ ) does run into
pr39959, but using --enable-checking=release gets around that problem.

Thanks.


-- 


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



[Bug tree-optimization/66110] New: uint8_t memory access not optimized

2015-05-11 Thread kevin at koconnor dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

Bug ID: 66110
   Summary: uint8_t memory access not optimized
   Product: gcc
   Version: 5.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: kevin at koconnor dot net
  Target Milestone: ---

It appears that gcc does not do a good job of optimizing memory accesses to
'uint8_t' variables.  In particular, it appears as if "strict aliasing" is not
done on uint8_t variables, and it appears it is not done even if the uint8_t is
in a struct.

 GCC version:

$ ~/src/install-5.1.0/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/kevin/src/install-5.1.0/bin/gcc
COLLECT_LTO_WRAPPER=/home/kevin/src/install-5.1.0/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-5.1.0/configure --prefix=/home/kevin/src/install-5.1.0
--enable-languages=c
Thread model: posix
gcc version 5.1.0 (GCC) 

=== Compile command line:

~/src/install-5.1.0/bin/gcc -v -save-temps -O2 -Wall u8alias.c -c

=== Contents of u8alias.c:

typedef __UINT8_TYPE__ uint8_t;
typedef __UINT16_TYPE__ uint16_t;

struct s1 {
uint16_t f1;
uint8_t f2;
};

struct s2 {
struct s1 *p1;
};

void f1(struct s2 *p)
{
p->p1->f2 = 9;
p->p1->f2 = 10;
}

=== Contents of u8alias.i:

# 1 "u8alias.c"
# 1 ""
# 1 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "" 2
# 1 "u8alias.c"
typedef unsigned char uint8_t;
typedef short unsigned int uint16_t;

struct s1 {
uint16_t f1;
uint8_t f2;
};

struct s2 {
struct s1 *p1;
};

void f1(struct s2 *p)
{
p->p1->f2 = 9;
p->p1->f2 = 10;
}

=== Results of compilation:

$ objdump -ldr u8alias.o

 :
f1():
   0:   48 8b 07mov(%rdi),%rax
   3:   c6 40 02 09 movb   $0x9,0x2(%rax)
   7:   48 8b 07mov(%rdi),%rax
   a:   c6 40 02 0a movb   $0xa,0x2(%rax)
   e:   c3  retq   

=== Expected results:

I expected the second redundant load to be eliminated - for example, clang
produces this assembler (after replacing the gcc specific uint8_t typedefs with
an include of ):

$ clang -Wall -O2 u8alias.c -c
$ objdump -ldr u8alias.o

 :
f1():
   0:   48 8b 07mov(%rdi),%rax
   3:   c6 40 02 0a movb   $0xa,0x2(%rax)
   7:   c3  retq   

=== Other notes:

If the code is changed so that there are two redundant writes to ->f1 then gcc
does properly optimize away the first store.  Also, if the above definition of
f2 is changed to an 8-bit bitfield (ie, "uint8_t f2 : 8;") then gcc does
properly optimize away the first store.

This occurs on other platforms besides x86_64.  (In particular, it happens on
avr-gcc where 8-bit integers are very common.)  I reproduced the above on gcc
5.1.0, but I've also seen it on variants of gcc 4.8 and gcc 4.9.

My guess is that the above is the result of an interpretation of the C99
specification - in particular section 6.5:

  An object shall have its stored value accessed only by an lvalue expression
that has one of the following types:
[...]
  -- a character type.

However, I do not think that should apply to the above test case for either of
the two following reasons:

1 - the memory access was not to a character type, it was to an integer type
that happened to be 1 byte in size (ie, a uint8_t type)
2 - the memory access was not to a character type, it was to a member of
'struct s1'.

As noted above, clang (eg, 3.4.2) does perform the expected optimization.


[Bug tree-optimization/66110] uint8_t memory access not optimized

2015-05-11 Thread kevin at koconnor dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

Kevin OConnor  changed:

   What|Removed |Added

 Resolution|INVALID |FIXED

--- Comment #2 from Kevin OConnor  ---
I understand that it is not incorrect to produce two redundant stores with the
sample code.  However, I do believe it would be correct to produce a single
store.

As such, I think this is an opportunity to improve gcc's optimization.  That
is, I think gcc could validly interpret the C spec so that two redundant
uint8_t stores could be replaced with one.

If this is not the best place to discuss that, what would be the best forum?


[Bug middle-end/66110] uint8_t memory access not optimized

2015-05-13 Thread kevin at koconnor dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

--- Comment #8 from Kevin OConnor  ---
Thanks!  I can confirm the latest trunk performs the desired optimization.

However, this test case still isn't fully optimized:

void f2(struct s1 *ps1, uint8_t *pi8)
{
ps1->f1 = 3;
*pi8 = 8;
ps1->f1 += 2;
}

That is, an "uint8_t*" still aliases with every other type. The "struct"
optimization is more important for my usage, but it is unfortunate that
uint8_t*/int8_t* are pessimized.  (In particular, there does not appear to be
any way to declare a pointer to an 8 bit integer that doesn't alias every other
type.)

I can open a separate bugzilla entry on the above.


[Bug middle-end/66110] uint8_t memory access not optimized

2015-05-18 Thread kevin at koconnor dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

--- Comment #10 from Kevin OConnor  ---
I've looked through the C specs (both C99 and C11) and I don't see anything
that requires uint8_t (nor int8_t) to be considered "character types".  I do
see three relevant sections in the spec which I'm including below.

For aliasing there is section 6.5:

  7 An object shall have its stored value accessed only by an lvalue expression
that has one of the following types:
  [...]
  -- a character type.

For "character types" there is section 6.2.5:

  15 The three types char, signed char, and unsigned char are collectively
called the character types. [...]

For uint8_t there is section 7.20.1.1:

 7.20.1.1 Exact-width integer types

  1 The typedef name intN_t designates a signed integer type with width N , no
padding bits, and a two's complement representation. Thus, int8_t denotes such
a signed integer type with a width of exactly 8 bits.

  2 The typedef name uintN_t designates an unsigned integer type with width N
and no padding bits. Thus, uint24_t denotes such an unsigned integer type with
a width of exactly 24 bits.

So, my read is that uint8_t must be considered an integer type, but is not
required to be considered a "character type".

That said, I understand that changing uint8_t may cause problems for some
existing user-code.  I'd think those enabling -fstrict-aliasing would want the
optimization benefit though.

I certainly understand if the cost of introducing another integer type and the
potential cost of causing issues for existing code is considered too high.  It
is unfortunate, though, that there doesn't appear to currently be any way to
declare a pointer to a non-aliasing 8-bit integer (that doesn't involve
'struct' hacks).


[Bug middle-end/66110] uint8_t memory access not optimized

2015-05-18 Thread kevin at koconnor dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

--- Comment #12 from Kevin OConnor  ---
(In reply to Andreas Schwab from comment #11)
> Since typedef does not create a new type the effect of uint8_t is exactly
> the same as the type it is defined from.  Thus if uint8_t is defined from
> unsigned char then uint8_t is a character type.

Yes, of course.  My point is that gcc does not need to define uint8_t /
__UINT8_TYPE__ as 'unsigned char'.  Instead it could define it as a new integer
type (eg, __gcc_uint8_t) that is an 8-bit integer that does not alias.

As before, I understand if the cost of doing this is too high, but it's
unfortunate that there currently does not appear to be any way to define a
pointer to an 8-bit integer that doesn't alias.


[Bug middle-end/66110] uint8_t memory access not optimized

2015-05-18 Thread kevin at koconnor dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66110

--- Comment #14 from Kevin OConnor  ---
(In reply to jos...@codesourcery.com from comment #13)
> I concur that it would be valid to define those typedefs to be extended 
> integer types withing the special aliasing properties.  The first 
> suggestion of that on the GCC lists that I know of is 
> .  However, it was noted 
> in  that there would be 
> C++ issues.  I see that C++ does now have extended integer types, which it 
> didn't at that time, but there would still be questions of mangling 
> (changing typedefs from standard headers breaks the library ABI for 
> anything using those types in C++ interfaces, because of changed 
> mangling).  And of course the question of what expectations might be 
> broken in C by making these typedefs into extended integer types.

Many thanks.  Those links and the background information is quite helpful.  I
agree that breaking the C++ ABI would not make sense on the major platforms.

> Cf  implementing 
> a char_no_alias_everything attribute.

I do think having something like "char_no_alias_everything" would be useful. 
My interest in this discussion was due to the code generation on the embedded
AVR platform (where 8-bit integers are very common).  If non-aliasing 8-bit
integer types existed, I suspect dealing with ABI breakage would be more
tenable on AVR.  (And if nothing else, utilizing them within an individual AVR
project would not be difficult.)