This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
why GCC does implicit promotion to unsigned char?
- From: Konstantin Vladimirov <konstantin dot vladimirov at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 26 Jan 2012 14:27:45 +0400
- Subject: why GCC does implicit promotion to unsigned char?
Hi,
Consider code:
char A;
char B;
char sum_A_B ( void )
{
char sum = A + B;
return sum;
}
Compile it on any backend (for example x86):
gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292]
gcc -m32 -O2 -S repro.c -fdump-tree-all-lineno-details
Now look at repro.c.004t.gimple:
sum_A_B ()
[repro.c : 5:1] {
char A.0;
unsigned char A.1;
char B.2;
unsigned char B.3;
unsigned char D.1990;
char D.1991;
char sum;
[repro.c : 6:8] A.0 = A;
[repro.c : 6:8] A.1 = (unsigned char) A.0;
[repro.c : 6:8] B.2 = B;
[repro.c : 6:8] B.3 = (unsigned char) B.2;
[repro.c : 6:8] D.1990 = A.1 + B.3;
[repro.c : 6:8] sum = (char) D.1990;
[repro.c : 8:3] D.1991 = sum;
[repro.c : 8:3] return D.1991;
}
It looks really weird. Why gcc promotes char to unsigned char internally?
This case is simple repro, but in my production code it is a reason of
productivity overhead (vectorizer fails on such promotions).
Thanks in advance for any responses. Previous discussion about inline
assembler was really helpful.
---
With best regards, Konstantin