This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/67334] New: [4.7 arm inline-asm] inline assembly incorrect register allocation
- From: "anmin_deng at yahoo dot com.tw" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 24 Aug 2015 06:55:36 +0000
- Subject: [Bug inline-asm/67334] New: [4.7 arm inline-asm] inline assembly incorrect register allocation
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67334
Bug ID: 67334
Summary: [4.7 arm inline-asm] inline assembly incorrect
register allocation
Product: gcc
Version: 4.7.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: inline-asm
Assignee: unassigned at gcc dot gnu.org
Reporter: anmin_deng at yahoo dot com.tw
Target Milestone: ---
A very simple code with ARM inline assembly
== "test.c" ==>
extern unsigned x;
extern unsigned s;
void
h(void)
{
unsigned a, b, c, d;
unsigned i;
__asm__ volatile ("mrrc p15,2,%0,%1,c14" : "=r"(a),"=r"(b));
i = 12000000;
__asm__ volatile ("\n"
" adds %0,%2,%4\n"
" adc %1,%3,$0"
: "=r"(c),"=r"(d)
: "r"(a),"r"(b),"r"(i) : "cc");
__asm__ volatile ("mcrr p15,2,%0,%1,c14" : : "r"(c),"r"(d));
if (a == x) {
++s;
}
}
<===
To compile the above simple test code on PC cygwin with ARM target
cross-compiler and "-Os" options:
"arm-none-eabi-gcc -ansi -Wall -W -Os -mcpu=cortex-a7 test.c -S".
The generated result is allocating incorrect register...
=== "test.s" ===>
...
h:
...
@ 9 "test.c" 1
mrrc p15,2,r3,r2,c14
@ 0 "" 2
ldr r1, .L3
@ 11 "test.c" 1
adds r2,r3,r1 @INCORRECT! reg "r2" allocated, "@ 9" above corrupted
adc r1,r2,$0
@ 0 "" 2
@ 16 "test.c" 1
mcrr p15,2,r2,r1,c14
@ 0 "" 2
...
<===
On the other hand, to compile with "-O2" option
"arm-none-eabi-gcc -ansi -Wall -W -O2 -mcpu=cortex-a7 test.c -S",
the generated result is OK.
--
Details about this "ARM target cross-compiler"..
arm-none-eabi-gcc -ansi -Wall -W -Os -mcpu=cortex-a7 test.c -S -v -save-temps
>>
Using built-in specs.
COLLECT_GCC=/cygdrive/c/tool-chain/arm-none-eabi-gcc
Target: arm-none-eabi
Configured with: ../gcc-4.7.4/configure LDFLAGS=--static
--prefix='/cygdrive/c/tool-chain' --target=arm-none-eabi --build=i686-pc-cygwin
--host=i686-pc-cygwin --with-sysroot='/cygdrive/c/tool-chain' --with-gnu-as
--with-gnu-ld --with-float=soft --disable-threads --with-stabs --disable-nls
--disable-host-shared --disable-shared --with-tls=gnu2 --with-newlib
--without-headers --disable-biendian --disable-initfini-array
--enable-version-specific-runtime-libs --enable-languages=c,c++
--disable-libssp --disable-libquadmath --disable-libgomp --disable-libvtv
--disable-lto --disable-add-ons --enable-target-optspace --disable-profile
--disable-nss-crypt --disable-nss --enable-cloog-backend=isl
--with-host-libstdcxx=-Wl,-Bstatic,-lstdc++,-lm
--with-mpc=/cygdrive/u/develop/tool_chain/prerequisites-4.7.4
--with-mpfr=/cygdrive/u/develop/tool_chain/prerequisites-4.7.4
--with-gmp=/cygdrive/u/develop/tool_chain/prerequisites-4.7.4
--with-ppl=/cygdrive/u/develop/tool_chain/prerequisites-4.7.4
--with-isl=/cygdrive/u/develop/tool_chain/prerequisites-4.7.4
--with-cloog=/cygdrive/u/develop/tool_chain/prerequisites-4.7.4
Thread model: single
gcc version 4.7.4 (GCC)
COLLECT_GCC_OPTIONS='-ansi' '-Wall' '-Wextra' '-Os' '-mcpu=cortex-a7' '-S' '-v'
'-save-temps' '-mfloat-abi=soft' '-mtls-dialect=gnu2'
/cygdrive/c/tool-chain/bin/../libexec/gcc/arm-none-eabi/4.7.4/cc1.exe -E
-quiet -v -iprefix /cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/
-isysroot /cygdrive/c/tool-chain/bin/../../tool-chain -D__USES_INITFINI__
test.c -mcpu=cortex-a7 -mfloat-abi=soft -mtls-dialect=gnu2 -ansi -Wall -Wextra
-Os -fpch-preprocess -o test.i
....
#include "..." search starts here:
#include <...> search starts here:
/cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/include
/cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/include-fixed
/cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/include
End of search list.
COLLECT_GCC_OPTIONS='-ansi' '-Wall' '-Wextra' '-Os' '-mcpu=cortex-a7' '-S' '-v'
'-save-temps' '-mfloat-abi=soft' '-mtls-dialect=gnu2'
/cygdrive/c/tool-chain/bin/../libexec/gcc/arm-none-eabi/4.7.4/cc1.exe
-fpreprocessed test.i -quiet -dumpbase test.c -mcpu=cortex-a7 -mfloat-abi=soft
-mtls-dialect=gnu2 -auxbase-strip test.s -Os -Wall -Wextra -ansi -version
GNU C (GCC) version 4.7.4 (arm-none-eabi)
compiled by GNU C version 4.8.3, GMP version 6.0.0, MPFR version
3.1.2-p10, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.7.4 (arm-none-eabi)
compiled by GNU C version 4.8.3, GMP version 6.0.0, MPFR version
3.1.2-p10, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 2291625f97745215868a9e7332f1f761
COMPILER_PATH=/cygdrive/c/tool-chain/bin/../libexec/gcc/arm-none-eabi/4.7.4/:/cygdrive/c/tool-chain/bin/../libexec/gcc/:/cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/bin/
LIBRARY_PATH=/cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/:/cygdrive/c/tool-chain/bin/../lib/gcc/:/cygdrive/c/tool-chain/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/:/cygdrive/c/tool-chain/bin/../../tool-chain/lib/
COLLECT_GCC_OPTIONS='-ansi' '-Wall' '-Wextra' '-Os' '-mcpu=cortex-a7' '-S' '-v'
'-save-temps' '-mfloat-abi=soft' '-mtls-dialect=gnu2'
<<