Hi all,

Can gatekeeper help review bug940? Thanks.
https://bugs.open64.net/show_bug.cgi?id=940
case:
int main()
{
 int inc = 0xFFFF;
 asm volatile (
  "add $1, %0\n\t"
  : "+Q" (inc)
  :
  );
printf("inc=%d\n",inc);
}
$opencc case.c –O0
./a.out
inc=34  // a random number
$gcc case.c –O0
./a.out
inc=65536

Analyze:
the output of .s from open64 is:
#   3   int inc = 0xFFFF;
        movl $65535,%edi                # [0]
        movl %edi,-12(%rbp)             # [0] inc
        .loc    1       4       0
 #   4   asm volatile (
        movl -12(%rbp),%eax             # [0] inc
        add $1, %edx  // edx never defined before

        movzbl %dl,%eax                 # [0]

The problem is at function Adjust_one_eight_bit_reg, it will insert a
movzbl op.
The tree before:
[   4, 0] TN158 :- asm TN158<defopnd> ; volatile side_effects
After:
[   4, 0] TN160(%rdx) :- asm TN158(%rax) ; volatile side_effects
[   4, 0] TN158(%rax) :- movzbl TN160(%rdx) ;
For asm volatile (
  "add $1, %0\n\t"
  : "+Q" (inc)
before insert, TN158 is both input and output of asm. For inline asm if the
input and ouput are the same, we need to make sure they use the same TN,
stored in the same register. So it need to insert another mov from TN158 to
TN160 before asm.
such as:
[   4, 0] TN160 :- mov TN158 ; copy
[   4, 0] TN160 :- asm TN160 ; volatile side_effects
[   4, 0] TN158 :- mov32 TN160 ; copy

Thanks
zhuqing

Attachment: bug940.patch
Description: Binary data

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to