On the following test case, gcc generates (seemingly?) incorrect assembly.
Command line is: gcc -Wall -o tst2_b.s -S tst2_b.c
Note: the test case does not include any header.
%---- source code -----
typedef void *my_t __attribute__((aligned(16)));
void f(void *a, my_t b) {}
void g(void) {
void *ptr1;
void *ptr2;
f(ptr1, ptr2);
}
%----------------------
The caller's registers (r36, r37) incorrectly become (r32, r34) callee's
registers while the CPU actually "renames" r37 into r33.
%---- Assembly --------
.file "tst2_b.c"
.pred.safe_across_calls p1-p5,p16-p63
.text
.align 16
.global f#
.proc f#
f:
.prologue 2, 2
.vframe r2
mov r2 = r12
adds r12 = -16, r12
.body
;;
adds r14 = -16, r2
;;
st8 [r14] = r32 <=================================
mov r14 = r2
;;
st8 [r14] = r34 <=================================
.restore sp
mov r12 = r2
br.ret.sptk.many b0
;;
.endp f#
.align 16
.global g#
.proc g#
g:
.prologue 14, 32
.save ar.pfs, r33
alloc r33 = ar.pfs, 0, 4, 2, 0
.vframe r34
mov r34 = r12
adds r12 = -16, r12
mov r35 = r1
.save rp, r32
mov r32 = b0
.body
;;
adds r14 = 8, r34
;;
ld8 r36 = [r14] <====================================
ld8 r37 = [r34] <====================================
br.call.sptk.many b0 = f#
mov r1 = r35
;;
mov ar.pfs = r33
mov b0 = r32
.restore sp
mov r12 = r34
br.ret.sptk.many b0
;;
.endp g#
.ident "GCC: (GNU) 4.0.2 (Debian 4.0.2-2)"
%----------------------
In comparison, the following test case generates correct assembly.
%---- source code -----
typedef void *my_t __attribute__((aligned(16)));
void f(void *a, my_t b) {}
void g(void) {
void *ptr1;
my_t ptr2;
f(ptr1, ptr2);
}
%----------------------
Here, the mapping between caller's registers (r36, r38) and callee's registers
(r32, r34) is ok.
%---- Assembly --------
.file "tst2_a.c"
.pred.safe_across_calls p1-p5,p16-p63
.text
.align 16
.global f#
.proc f#
f:
.prologue 2, 2
.vframe r2
mov r2 = r12
adds r12 = -16, r12
.body
;;
adds r14 = -16, r2
;;
st8 [r14] = r32 <===========================
mov r14 = r2
;;
st8 [r14] = r34 <===========================
.restore sp
mov r12 = r2
br.ret.sptk.many b0
;;
.endp f#
.align 16
.global g#
.proc g#
g:
.prologue 14, 32
.save ar.pfs, r33
alloc r33 = ar.pfs, 0, 4, 3, 0
.vframe r34
mov r34 = r12
adds r12 = -16, r12
mov r35 = r1
.save rp, r32
mov r32 = b0
.body
;;
adds r14 = 8, r34
;;
ld8 r36 = [r14] <=====================================
ld8 r38 = [r34] <=====================================
br.call.sptk.many b0 = f#
mov r1 = r35
;;
mov ar.pfs = r33
mov b0 = r32
.restore sp
mov r12 = r34
br.ret.sptk.many b0
;;
.endp g#
.ident "GCC: (GNU) 4.0.2 (Debian 4.0.2-2)"
%----------------------
Output of gcc -v:
%----------------------
Using built-in specs.
Target: ia64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --with-system-libunwind --enable-checking=release
ia64-linux-gnu
Thread model: posix
gcc version 4.0.2 (Debian 4.0.2-2)
%----------------------
--
Olivier Aumage
--
Summary: Aligned args on IA64
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: olivier dot aumage at labri dot fr
GCC host triplet: ia64-linux-gnu
GCC target triplet: ia64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25372