public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/105193] New: Code divergence based on -fdump-tree-* since r9-5080-gf7293b9dfab5e6e7
@ 2022-04-07  9:43 marxin at gcc dot gnu.org
  2022-04-07  9:44 ` [Bug ipa/105193] " marxin at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-07  9:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105193

            Bug ID: 105193
           Summary: Code divergence based on -fdump-tree-* since
                    r9-5080-gf7293b9dfab5e6e7
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: hubicka at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

The following code diverges:

$ cat NodeImpl.ii
struct NodeImpl {
  virtual bool isAttrImpl();
  void deleteIf();
  virtual int getOwnerDocument();
  void unreferenced();
  bool isOwned();
};
struct AttrImpl : NodeImpl {
  bool isAttrImpl();
};
bool NodeImpl::isAttrImpl() { return false; }
NodeImpl *deleteIf_thisNode;
void NodeImpl::deleteIf() {
  if (isOwned())
    return;
  isAttrImpl();
  ((AttrImpl *)deleteIf_thisNode)->getOwnerDocument();
}
void NodeImpl::unreferenced() { deleteIf(); }

$ g++ -O2 NodeImpl.ii -c -S -o 1.s -fdump-tree-all=/dev/null && g++ -O2
NodeImpl.ii -c -S -o 2.s && diff -u [12].s
--- 1.s 2022-04-07 11:43:05.995744783 +0200
+++ 2.s 2022-04-07 11:43:06.023744659 +0200
@@ -27,8 +27,10 @@
        testb   %al, %al
        jne     .L3
        movq    0(%rbp), %rax
-       movq    %rbp, %rdi
-       call    *(%rax)
+       movq    (%rax), %rax
+       cmpq    $_ZN8NodeImpl10isAttrImplEv, %rax
+       jne     .L10
+.L5:
        movq    deleteIf_thisNode(%rip), %rdi
        popq    %rbp
        .cfi_remember_state
@@ -41,8 +43,16 @@
 .L3:
        .cfi_restore_state
        popq    %rbp
+       .cfi_remember_state
        .cfi_def_cfa_offset 8
        ret
+       .p2align 4,,10
+       .p2align 3
+.L10:
+       .cfi_restore_state
+       movq    %rbp, %rdi
+       call    *%rax
+       jmp     .L5
        .cfi_endproc
 .LFE1:
        .size   _ZN8NodeImpl8deleteIfEv, .-_ZN8NodeImpl8deleteIfEv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug ipa/105193] Code divergence based on -fdump-tree-* since r9-5080-gf7293b9dfab5e6e7
  2022-04-07  9:43 [Bug ipa/105193] New: Code divergence based on -fdump-tree-* since r9-5080-gf7293b9dfab5e6e7 marxin at gcc dot gnu.org
@ 2022-04-07  9:44 ` marxin at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-07  9:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105193

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-04-07
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
It's speculative devirtualization that plays the role:

$ g++ -O2 NodeImpl.ii -c -S -o 1.s -fdump-tree-all=/dev/null
-fdump-tree-optimized=1 && g++ -O2 NodeImpl.ii -c -S -o 2.s
-fdump-tree-optimized=2 && diff -u 1 2
--- 1   2022-04-07 11:43:51.739540416 +0200
+++ 2   2022-04-07 11:43:51.767540290 +0200
@@ -12,7 +12,8 @@

 ;; Function NodeImpl::deleteIf (_ZN8NodeImpl8deleteIfEv, funcdef_no=1,
decl_uid=2352, cgraph_uid=2, symbol_order=2)

-Removing basic block 5
+Removing basic block 7
+Removing basic block 8
 void NodeImpl::deleteIf (struct NodeImpl * const this)
 {
   bool _6;
@@ -22,25 +23,35 @@
   struct NodeImpl * _10;
   int (*) () * _11;
   int (*) () _12;
+  void * PROF_13;

   <bb 2> [local count: 1073741824]:
   _6 = NodeImpl::isOwned (this_4(D));
   if (_6 != 0)
-    goto <bb 4>; [34.00%]
+    goto <bb 6>; [34.00%]
   else
     goto <bb 3>; [66.00%]

   <bb 3> [local count: 708669601]:
   _7 = this_4(D)->_vptr.NodeImpl;
   _8 = *_7;
+  PROF_13 = [obj_type_ref] OBJ_TYPE_REF(_8;(struct NodeImpl)this_4(D)->0);
+  if (PROF_13 == isAttrImpl)
+    goto <bb 5>; [80.00%]
+  else
+    goto <bb 4>; [20.00%]
+
+  <bb 4> [local count: 141733922]:
   OBJ_TYPE_REF(_8;(struct NodeImpl)this_4(D)->0) (this_4(D));
+
+  <bb 5> [local count: 708669601]:
   deleteIf_thisNode.1_9 = deleteIf_thisNode;
   _10 = &MEM[(struct AttrImpl *)deleteIf_thisNode.1_9].D.2378;
   _11 = MEM[(struct AttrImpl *)deleteIf_thisNode.1_9].D.2378._vptr.NodeImpl;
   _12 = MEM[(int (*) () *)_11 + 8B];
   OBJ_TYPE_REF(_12;(struct NodeImpl)_10->1) (_10); [tail call]

-  <bb 4> [local count: 1073741824]:
+  <bb 6> [local count: 1073741824]:
   return;

 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-07  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07  9:43 [Bug ipa/105193] New: Code divergence based on -fdump-tree-* since r9-5080-gf7293b9dfab5e6e7 marxin at gcc dot gnu.org
2022-04-07  9:44 ` [Bug ipa/105193] " marxin 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).