public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/18562] New: SSE constant vector initialization produces dead constant values on stack
@ 2004-11-19  8:49 uros at gcc dot gnu dot org
  2004-11-19 14:44 ` [Bug target/18562] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: uros at gcc dot gnu dot org @ 2004-11-19  8:49 UTC (permalink / raw)
  To: gcc-bugs

Compiling this testcase with '-O2 -msse' an unoptimal code is produced. 'val1'
is merged into vector at compile time, but it is still loaded onto stack. Gcc
does not detect that 'val1' value on stack is sitting there unused.

#include <xmmintrin.h>
#include <stdio.h>

int main(void) {
	float val1 = 1.3f;
	float result[4];
	__m128 A;

	A = _mm_load1_ps(&val1);
	_mm_storeu_ps(result, A);

	printf("%f %f %f %f\n", result[0], result[1], result[2], result[3]);
	return 0;
}

This code is produced:
...
.LC2:                       <- merged vector
        .long   1067869798
        .long   0
        .long   0
        .long   0
        .text
        .p2align 4,,15
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $72, %esp
        movss   .LC2, %xmm0           <- vector is loaded into %xmm0
        andl    $-16, %esp
        subl    $16, %esp
        movl    $0x3fa66666, -4(%ebp) <- 'val1' is put on stack here
        shufps  $0, %xmm0, %xmm0
        movl    $.LC1, (%esp)
        movups  %xmm0, -20(%ebp)
        flds    -8(%ebp)
        fstpl   28(%esp)
        flds    -12(%ebp)
        fstpl   20(%esp)
        flds    -16(%ebp)
        fstpl   12(%esp)
        flds    -20(%ebp)
        fstpl   4(%esp)
        call    printf
        xorl    %eax, %eax
        leave
        ret

Even worser situation arises with:

int main(void) {
	float val1[4] = {1.3f, 1.4f, 1.5f, 1.6f};
	float result[4];
	__m128 A;

	A = _mm_loadu_ps(val1);
	_mm_storeu_ps(result, A);

	printf("%f %f %f %f\n", result[0], result[1], result[2], result[3]);
	return 0;

Following asm code is produced:
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $72, %esp
        andl    $-16, %esp
        movl    $0x3fa66666, -16(%ebp)
        subl    $16, %esp
        movl    $0x3fb33333, -12(%ebp)
        movl    $0x3fc00000, -8(%ebp)
        movl    $0x3fcccccd, -4(%ebp)
        movups  -16(%ebp), %xmm0
        movups  %xmm0, -32(%ebp)
        flds    -20(%ebp)
        fstpl   28(%esp)
        flds    -24(%ebp)
        fstpl   20(%esp)
        flds    -28(%ebp)
        fstpl   12(%esp)
        flds    -32(%ebp)
        fstpl   4(%esp)
        movl    $.LC4, (%esp)
        call    printf
        xorl    %eax, %eax
        leave
        ret

The constant values are not merged into vector at compile time, the vector is
built on the stack and then loaded into %xmm register. Value on stack is again
left unused after vector initialization.

Uros.

-- 
           Summary: SSE constant vector initialization produces dead
                    constant values on stack
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: uros at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 14+ messages in thread
[parent not found: <bug-18562-8427@http.gcc.gnu.org/bugzilla/>]
[parent not found: <bug-18562-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2021-07-26  2:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-19  8:49 [Bug tree-optimization/18562] New: SSE constant vector initialization produces dead constant values on stack uros at gcc dot gnu dot org
2004-11-19 14:44 ` [Bug target/18562] " pinskia at gcc dot gnu dot org
2004-11-19 15:41 ` uros at gcc dot gnu dot org
2005-01-11 23:58 ` rth at gcc dot gnu dot org
2005-01-12  6:53 ` uros at kss-loka dot si
2005-01-12  9:24 ` steven at gcc dot gnu dot org
2005-01-12  9:37 ` steven at gcc dot gnu dot org
2005-01-12 10:54 ` uros at kss-loka dot si
2005-01-18  9:49 ` rth at gcc dot gnu dot org
2005-01-18  9:52 ` rth at gcc dot gnu dot org
2005-09-14  6:51 ` pinskia at gcc dot gnu dot org
2005-09-14  7:09 ` pinskia at gcc dot gnu dot org
     [not found] <bug-18562-8427@http.gcc.gnu.org/bugzilla/>
2006-09-18  3:13 ` pinskia at gcc dot gnu dot org
     [not found] <bug-18562-4@http.gcc.gnu.org/bugzilla/>
2021-07-26  2:43 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).