[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-30 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #8 from Marc Glisse  ---
(In reply to Jakub Jelinek from comment #7)
> They are modelled in the .md files now, we just don't have general purpose
> builtins for this yet in GCC 4.9, it is only used for -fsanitize=undefined
> right now.

Ah, right, I thought you had only added an expander, nice that it is properly
modeled now (thanks), though I am yet to find C code where combine (or other)
ends up matching this pattern, which seems doable without a builtin. (well, we
are still losing the high half of the product if we use that pattern, but
that's less often needed)

Sorry for the hijack, back to comment 5 as the real motivation.


[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-30 Thread jakub at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #7 from Jakub Jelinek  ---
(In reply to Marc Glisse from comment #6)
> (In reply to Jakub Jelinek from comment #4)
> > Anyway, you definitely don't want
> > to use inline asm in this case, if there is some code GCC doesn't optimize
> > as good as you'd like to, just report that.
> 
> One common similar case where people are tempted to use asm goto with an
> output operand is, on x86: compute a*b and check if it overflowed. x86 has
> flags for that but AFAIR they are not modeled in the .md files. (I was also
> interested in output operands for asm goto in PR52381, but there is no good
> example there)

They are modelled in the .md files now, we just don't have general purpose
builtins for this yet in GCC 4.9, it is only used for -fsanitize=undefined
right now.


[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-30 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #6 from Marc Glisse  ---
(In reply to Jakub Jelinek from comment #4)
> Anyway, you definitely don't want
> to use inline asm in this case, if there is some code GCC doesn't optimize
> as good as you'd like to, just report that.

One common similar case where people are tempted to use asm goto with an output
operand is, on x86: compute a*b and check if it overflowed. x86 has flags for
that but AFAIR they are not modeled in the .md files. (I was also interested in
output operands for asm goto in PR52381, but there is no good example there)


[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-29 Thread hpa at zytor dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #5 from H. Peter Anvin  ---
Please don't get hung up on the specific example; I just picked one that was
small and self-contained.

The biggest reason we can't use gcc's native bits in the kernel are items where
we have to use the kernel's "alternative" feature, where the code is
dynamically patched.


[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-28 Thread jakub at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #4 from Jakub Jelinek  ---
But it would warn about it with -Wsign-compare.  You want unsigned r =
(unsigned) a + b; or similar to avoid undefined behavior if there is a
possibility of signed integer overflow.  Anyway, you definitely don't want to
use inline asm in this case, if there is some code GCC doesn't optimize as good
as you'd like to, just report that.


[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-28 Thread ubizjak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #3 from Uroš Bizjak  ---
(In reply to Uroš Bizjak from comment #2)

>   if (r < (unsigned) a)

Explicit cast is not needed here, the compiler will do it for you.

[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-28 Thread ubizjak at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

--- Comment #2 from Uroš Bizjak  ---
Looking at the assembly, you probably want:

--cut here--
int test (int a, int b, int c)
{
  unsigned r = a + b;

  if (r < (unsigned) a)
return 1;
  else if (r > c)
return 1;

  return 0;
}
--cut here--

gcc-4.8.2 -O2:

test:
addl%esi, %edi
movl$1, %eax
jc  .L2
xorl%eax, %eax
cmpl%edx, %edi
seta%al
.L2:
rep ret

Please note how the compiler is able to generate jc without compare insn.

[Bug c/59615] "asm goto" output or at least clobbered operands

2013-12-28 Thread jakub at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59615

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
The reason for the limitation is that any needed reload out can't be then
inserted after the asm goto, but all the other edges would need to be split and
the reload outs inserted on all the edges.

Looking at your example though, can you explain why you want to use asm goto
then?  I'd say that for addition, two conditional jumps and one comparison you
definitely don't want to use asm goto, the compiler can't see through it thus
can't optimize it.  Why isn't what GCC generates sufficient?  Do you have a
testcase?