[Bug target/19746] printf() optimisation ignores longcall attribute

2016-01-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19746

Martin Sebor  changed:

   What|Removed |Added

   Last reconfirmed|2005-05-09 01:18:53 |2016-1-27
 CC||msebor at gcc dot gnu.org
  Known to fail||5.3.0, 6.0

--- Comment #3 from Martin Sebor  ---
The behavior is still present on trunk and currently supported versions.  The
test case below shows the difference between the expected call sequence (in
bar_long) and the actual call sequence (in foo, which matches that in
bar_short).

That said, I don't think this is a target-specific problem.  The same issue
exists in other back ends, and is likely caused by some early folding not
taking into account differences in attributes or the presence of user-defined
declarations (as suggested by the patch in comment #2).

It seems that this bug should be reclassified as middle-end?

$ cat t.c && /build/sysroot/powerpc-eabispe/bin/powerpc-eabispe-gcc -O2 -S -o
/dev/stdout t.c
int printf (const char*, ...) __attribute__ ((__longcall__)); 
int puts (const char*) __attribute__ ((__longcall__));

void foo (void) { printf (" \n"); }

int puts_long (const char*) __attribute__ ((__longcall__));
int puts_short (const char*) __attribute__ ((__shortcall__));

void bar_long (void) { puts_long (" "); }
void bar_short (void) { puts_short (" "); }


.file   "t.c"
.section".text"
.align 2
.globl foo
.type   foo, @function
foo:
lis 3,.LC0@ha
la 3,.LC0@l(3)
b puts
.size   foo, .-foo
.align 2
.globl bar_long
.type   bar_long, @function
bar_long:
stwu 1,-8(1)
lis 9,puts_long@ha
mflr 0
la 9,puts_long@l(9)
lis 3,.LC0@ha
stw 0,12(1)
la 3,.LC0@l(3)
mtctr 9
bctrl
lwz 0,12(1)
addi 1,1,8
mtlr 0
blr
.size   bar_long, .-bar_long
.align 2
.globl bar_short
.type   bar_short, @function
bar_short:
lis 3,.LC0@ha
la 3,.LC0@l(3)
b puts_short
.size   bar_short, .-bar_short
.section.rodata.str1.4,"aMS",@progbits,1
.align 2
.LC0:
.string " "
.ident  "GCC: (GNU) 6.0.0 20160121 (experimental)"

[Bug target/19746] printf() optimisation ignores longcall attribute

2005-02-07 Thread amodra at bigpond dot net dot au

--- Additional Comments From amodra at bigpond dot net dot au  2005-02-07 
11:28 ---
Note that if you declare __builtin_printf and __builtin_puts with
__attribute__((__longcall__)) as well as printf and puts, you will get the
behaviour you expect.

The following patch also works, but I'm unsure of all the ramifications.  As far
as I can see, it seems that the only thing this will change is the name of the
function declaration used in implicit builtin expansions.

* c-common.c (builtin_function_2): Return normal decl rather than
built-in decl if it is available.

--- c-common.c~ 2005-02-07 21:17:05.660721258 +1030
+++ c-common.c  2005-02-07 21:48:16.568241150 +1030
@@ -3348,7 +3348,7 @@ builtin_function_2 (const char *builtin_
 decl = lang_hooks.builtin_function (name, type, function_code, cl,
NULL, attrs);
 
-  return (bdecl != 0 ? bdecl : decl);
+  return (decl != 0 ? decl : bdecl);
 }
 
 /* Nonzero if the type T promotes to int.  This is (nearly) the


-- 


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


[Bug target/19746] printf() optimisation ignores longcall attribute

2005-02-06 Thread amodra at bigpond dot net dot au

--- Additional Comments From amodra at bigpond dot net dot au  2005-02-07 
07:19 ---
Confirmed for current 3.4 branch and mainline.

-- 
   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever Confirmed||1
  Known to fail||4.0.0 3.4.4
   Last reconfirmed|-00-00 00:00:00 |2005-02-07 07:19:01
   date||


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