Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

more compact sequence of x86 movs generated when using -g #39939

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR40969
Status NEW
Importance P enhancement
Reported by Greg Bedwell (greg.bedwell@sony.com)
Reported on 2019-03-05 12:10:58 -0800
Last modified on 2019-09-29 01:48:03 -0700
Version trunk
Hardware PC Linux
CC cmtice@google.com, echristo@gmail.com, htmldeveloper@gmail.com, jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, paul_robinson@playstation.sony.com, praveenvelliengiri@gmail.com, vsk@apple.com, yechunliangcn@163.com
Fixed by commit(s)
Attachments
Blocks PR37728
Blocked by
See also
In response to this llvm-dev post: http://lists.llvm.org/pipermail/llvm-
dev/2019-March/130779.html

Here is an example using the check-cfc tool ( https://github.com/llvm/llvm-
project/tree/master/clang/utils/check_cfc ) to spot a codegen difference
depending on whether -g is specified or not.  The reduced source example is a
little bit nasty as there's some dodgy looking pointer casting in there, but
regardless the absence or presence of -g should not make a difference to
generated code.

Here's my check_cfc.cfg file contents:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Checks]
dash_g_no_change = true
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

and here it is in action:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ clang -v
Check CFC, checking: dash_g_no_change
clang version 9.0.0 (trunk 355410) (llvm/trunk 355412)
Target: x86_64-scei-ps4
Thread model: posix
InstalledDir: E:\work\upstream-llvm\build-vs2015-ps4-ninja\bin

$ cat 1.cpp

using alpha = float __attribute__((ext_vector_type(4)));

void bravo(alpha charlie) {
  unsigned char *delta = (unsigned char *)&charlie;
  delta[0] = 0;
  volatile alpha echo = charlie;
}

$ clang -c 1.cpp -O2 -g -fno-strict-aliasing --target=x86_64-unknown-unknown
Check CFC, checking: dash_g_no_change
1.cpp Code difference detected with -g
--- c:\tmp\gnochange\example\tmp\tmp_v5akp.o

+++ c:\tmp\gnochange\example\tmp\tmpvhabwu.o

@@ -5,6 +5,6 @@

 0x00000001: 48 89 E5                mov      rbp,rsp
 0x00000004: 0F 29 45 F0             movaps   xmmword ptr [rbp-10h],xmm0
 0x00000008: C6 45 F0 00             mov      byte ptr [rbp-10h],0
-0x0000000C: 0F 28 45 F0             movaps   xmm0,xmmword ptr [rbp-10h]
-0x00000010: 0F 29 45 E0             movaps   xmmword ptr [rbp-20h],xmm0
-0x00000014: 5D                      pop      rbp
+0x0000000C: 8A 45 F0                mov      al,byte ptr [rbp-10h]
+0x0000000F: 88 45 E0                mov      byte ptr [rbp-20h],al
+0x00000012: 48 8B 45 F1             mov      rax,qword ptr [rbp-0Fh]
*** Diff truncated ***
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quuxplusone commented 5 years ago
I have tested in linux,

with -g enabled:

0000000000000000 <_Z5bravoDv4_f>:
   0:   0f 29 44 24 d8          movaps %xmm0,-0x28(%rsp)
   5:   c6 44 24 d8 00          movb   $0x0,-0x28(%rsp)
   a:   0f 28 44 24 d8          movaps -0x28(%rsp),%xmm0
   f:   0f 29 44 24 e8          movaps %xmm0,-0x18(%rsp)
  14:   c3                      retq

with -g not enabled:

0000000000000000 <_Z5bravoDv4_f>:
   0:   0f 29 44 24 d8          movaps %xmm0,-0x28(%rsp)
   5:   c6 44 24 d8 00          movb   $0x0,-0x28(%rsp)
   a:   8a 44 24 d8             mov    -0x28(%rsp),%al
   e:   88 44 24 e8             mov    %al,-0x18(%rsp)
  12:   48 8b 44 24 d9          mov    -0x27(%rsp),%rax
  17:   48 89 44 24 e9          mov    %rax,-0x17(%rsp)
  1c:   8b 44 24 e1             mov    -0x1f(%rsp),%eax
  20:   89 44 24 f1             mov    %eax,-0xf(%rsp)
  24:   0f b7 44 24 e5          movzwl -0x1b(%rsp),%eax
  29:   66 89 44 24 f5          mov    %ax,-0xb(%rsp)
  2e:   8a 44 24 e7             mov    -0x19(%rsp),%al
  32:   88 44 24 f7             mov    %al,-0x9(%rsp)
  36:   c3                      retq
Quuxplusone commented 5 years ago

Candidate patch: https://reviews.llvm.org/D61680

Quuxplusone commented 5 years ago

Was this fixed by https://reviews.llvm.org/D61680?

Quuxplusone commented 5 years ago
I could not reproduce this issue by clang version 10.0.0
(https://github.com/llvm/llvm-project.git
9ebed3104629f30f12a1f3e391c767397a89d6a5)