Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise recorded into Type Feedback as a Callee #1293

Open
rihafilip opened this issue Jun 27, 2024 · 0 comments
Open

Promise recorded into Type Feedback as a Callee #1293

rihafilip opened this issue Jun 27, 2024 · 0 comments
Assignees
Labels

Comments

@rihafilip
Copy link
Collaborator

When running
PIR_LLVM_OPT_LEVEL=0 PIR_DEOPT_CHAOS=100000 PIR_DEOPT_CHAOS_NO_RETRIGGER=1 /home/rihafilip/r/rir/external/custom-r/bin/R -f ./test.r --no-init-file,
where ./test.r is attached, when we are deopting, a SEXP of type promise is recorded into the callees type feedback.

From native JITed code, the deoptImpl is called with deoptTrigger being a promise.

Attachments:
promise_tf.zip

Pir After Optimization:

┌──────────────────────────────────────────────────────────────────────────────┐
│ test[0x5555586a5dd0]                                                         │
│ Context: !ExpMi,CorrOrd,!TMany,Argmatch;Eager1,NonRefl1,!Obj1                │
│ Properties:                                                                  │
├────── PIR Version After Optimizations
test[0x5555586a5dd0]
BB0
  goto BB1
BB1   <- [0]
  val?~+          %1.0  = LdArg                    1
  val?^           %1.1  = LdArg                    0
  cp              %1.2  = Checkpoint                -> BB2 (default) | BB34 (if assume failed)
BB2   <- [1]
  val?^ | miss    %2.0  = LdVar              eR    rir.compile, R_GlobalEnv
  lgl$#-          %2.1  = Identical                %2.0, function(what) <(rir::DispatchTable*)0x555557b|...
  void                    Assume             D     %2.1, %1.2 (CallTarget@0x55555700c608[Call#0])
  env             e2.3  = MkEnv              l     f=%1.1, expected=%1.0, parent=R_GlobalEnv, context 1
  prom-           %2.4  = MkArg                    unboundValue, test[0x5555586a5dd0]_p0, e2.3
  ct              %2.5  = PushContext        lCL   %2.4, rir.compile(f), function(what) <(rir::DispatchTable*)0x555557b|..., e2.3
  val?^           %2.6  = CastType                 up %2.4
  val?^ | miss    %2.7  = LdVar              eR    .Call, R_GlobalEnv
  lgl$#-          %2.8  = Identical                <blt .Call>, %2.7   <true>
  cp              %2.9  = Checkpoint                -> BB4 (default) | BB3 (if assume failed)
BB34   <- [1]
  env             e34.0 = (MkEnv)            l     f=%1.1, expected=%1.0, parent=R_GlobalEnv, context 1
  fs              %34.1 = FrameState         R     0x555555bc41e0+0: [], env=e34.0
  void                    Deopt              !v    %34.1
BB4   <- [2]
  void                    Assume             D     %2.8, %2.9 (DeadBranchReached@0x55555700c818[Test#0])
  env             e4.1  = MkEnv              l     what=%2.6, parent=R_GlobalEnv, context 1
  val?            %4.2  = Force!<lazy>       !vL   %2.6, e4.1   <cls->
  val?            %4.3  = CallBuiltin        !v    .Call("rirCompile", %4.2) e4.1   <cls->
  val?            %4.4  = PopContext         C     %4.3, %2.5   <cls->
  void                    StVar              lW    f, %4.4, e2.3
  cp              %4.6  = Checkpoint                -> BB6 (default) | BB5 (if assume failed)
BB3   <- [2]
  fs              %3.0  = FrameState         R     0x555555bc41e0+32: [], env=e2.3
  env             e3.1  = (MkEnv)            l     what=%2.6, parent=R_GlobalEnv, context 1
  fs              %3.2  = FrameState         R     0x555557b8faa0+17: [<blt .Call>, %2.8], env=e3.1, next=%3.0
  void                    Deopt              !v    %3.2   !
BB6   <- [4]
  val?^ | miss    %6.0  = LdVar              eR    testrir, e2.3
  lgl$#-          %6.1  = IsType                   %6.0 isA lgl$-
  void                    Assume             D     %6.1, %4.6 (Typecheck@0x55555700c608[Type#2])
  lgl$-           %6.3  = CastType           d     dn %6.0
  lgl$#-          %6.4  = CheckTrueFalse     e     %6.3
  void                    Branch                   %6.4 -> BB25 (if true) | BB7 (if false)
BB5   <- [4]
  fs              %5.0  = FrameState         R     0x555555bc41e0+46: [], env=e2.3
  void                    Deopt              !v    %5.0   !
BB25   <- [6]
  (cls|spec|blt)  %25.0 = LdFun              !v    f, <%4.4>, e2.3
  val?            %25.1 = Call               !v    %25.0() e2.3   <val?$->
  void                    StVar              lW    res, %25.1, e2.3
  cp              %25.3 = Checkpoint                -> BB27 (default) | BB26 (if assume failed)
BB7   <- [6]
  goto BB8
BB27   <- [25]
  val?^ | miss    %27.0 = LdVar              eR    paste, e2.3
  lgl$#-          %27.1 = Identical                %27.0, function(..., sep=" ", collapse=NULL, recycle0|...
  void                    Assume             D     %27.1, %25.3 (CallTarget@0x55555700c608[Call#2])
  prom-           %27.3 = MkArg                    unboundValue, test[0x5555586a5dd0]_p5 (!refl), e2.3
  prom-           %27.4 = MkArg                    unboundValue, test[0x5555586a5dd0]_p6, e2.3
  dots-           %27.5 = DotsList           l     %27.3, %27.4
  val?^ | miss    %27.6 = CastType                 up %27.4
  env             e27.7 = MkEnv              l     ...=%27.5, sep(miss)=" ", collapse(miss)=nil, recycle0(miss)=false, parent=R_BaseNamespace, context 0
  val?            %27.8 = Force!             !vL   %27.6, e27.7
  val+            %27.9 = CallSafeBuiltin    wed   list(%25.1, %27.8)    <vec->
  val+            %27.10 = CallSafeBuiltin    wed   paste(%27.9, " ", nil, false)    <str$->
  val?^ | miss    %27.11 = LdVar              eR    expected, e2.3
  val?            %27.12 = Force!<lazy>       !v    %27.11, e2.3   <str$->
  lgl$#-          %27.13 = IsType                   %27.12 isA val?-
  lgl$#-          %27.14 = IsType                   %27.10 isA val?-
  cp              %27.15 = Checkpoint                -> BB29 (default) | BB28 (if assume failed)
BB26   <- [25]
  fs              %26.0 = FrameState         R     0x555555bc41e0+112: [], env=e2.3
  void                    Deopt              !v    %26.0   !
BB8   <- [7, 32]
  (cls|spec|blt)  %8.0  = LdFun              !v    f, e2.3
  val?            %8.1  = Call               !v    %8.0() e2.3
  (cls|spec|blt)  %8.2  = LdFun              !v    f, e2.3
  val?            %8.3  = Call               !v    %8.2() e2.3
  (cls|spec|blt)  %8.4  = LdFun              !v    f, e2.3
  val?            %8.5  = Call               !v    %8.4() e2.3
  cp              %8.6  = Checkpoint                -> BB10 (default) | BB9 (if assume failed)
BB29   <- [27]
  void                    Assume             D     %27.14, %27.15 (Typecheck@0x55555700c608[Type#7])
  val-            %29.1 = CastType           d     dn %27.10   <str$->
  void                    Assume             D     %27.13, %27.15 (Typecheck@0x55555700c608[Type#8])
  val?-           %29.3 = CastType           d     dn %27.12   <str$->
  lgl-            %29.4 = Neq                wed   %29.1, %29.3, elided   <lgl$->
  lgl$#-          %29.5 = IsType                   %29.4 isA lgl$-
  cp              %29.6 = Checkpoint                -> BB31 (default) | BB30 (if assume failed)
BB28   <- [27]
  fs              %28.0 = FrameState         R     0x555555bc41e0+163: [%27.10, %27.12], env=e2.3
  void                    Deopt              !v    %28.0   !
BB10   <- [8]
  val?^ | miss    %10.0 = LdVar              eR    pir.compile, e2.3
  lgl$#-          %10.1 = Identical                %10.0, function(what, debugFlags, debugStyle, P_EARLY|...
  void                    Assume             D     %10.1, %8.6 (CallTarget@0x55555700c608[Call#9])
  prom-           %10.3 = MkArg                    unboundValue, test[0x5555586a5dd0]_p1, e2.3
  ct              %10.4 = PushContext        lCL   %10.3, pir.compile(f), function(what, debugFlags, debugStyle, P_EARLY|..., e2.3
  val?^           %10.5 = CastType                 up %10.3
  cp              %10.6 = Checkpoint                -> BB12 (default) | BB11 (if assume failed)
BB9   <- [8]
  fs              %9.0  = FrameState         R     0x555555bc41e0+331: [%8.5], env=e2.3
  void                    Deopt              !v    %9.0   !
BB31   <- [29]
  void                    Assume             D     %29.5, %29.6 (Typecheck@0x55555700c608[Type#9])
  lgl$-           %31.1 = CastType           d     dn %29.4
  lgl$#-          %31.2 = CheckTrueFalse     e     %31.1
  void                    Branch                   %31.2 -> BB33 (if true) | BB32 (if false)
BB30   <- [29]
  fs              %30.0 = FrameState         R     0x555555bc41e0+169: [%29.4], env=e2.3
  void                    Deopt              !v    %30.0   !
BB12   <- [10]
  val?^ | miss    %12.0 = LdVar              eR    .Call, R_GlobalEnv
  lgl$#-          %12.1 = Identical                <blt .Call>, %12.0   <true>
  void                    Assume             D     %12.1, %10.6 (DeadBranchReached@0x555557c41840[Test#0])
  env             e12.3 = MkEnv              l     what=%10.5, debugFlags=nil, debugStyle=nil, P_EARLY(miss)=false, P_FINAL(miss)=false, P_OPT(miss)=false, WARN(miss)=false, parent=R_GlobalEnv, context 1
  val?            %12.4 = Force!<lazy>       !vL   %10.5, e12.3   <cls->
  cp              %12.5 = Checkpoint                -> BB14 (default) | BB13 (if assume failed)
BB11   <- [10]
  fs              %11.0 = FrameState         R     0x555555bc41e0+364: [], env=e2.3
  env             e11.1 = (MkEnv)            l     what=%10.5, debugFlags(miss)=missingArg, debugStyle(miss)=missingArg, P_EARLY(miss)=false, P_FINAL(miss)=false, P_OPT(miss)=false, WARN(miss)=false, parent=R_GlobalEnv, context 1
  fs              %11.2 = FrameState         R     0x555557b5b4c0+0: [], env=e11.1, next=%11.0
  void                    Deopt              !v    %11.2   !
BB33   <- [31]
  (cls|spec|blt)  %33.0 = LdFun              !v    stop, e2.3
  fs              %33.1 = FrameState         R     0x555555bc41e0+190: [%33.0], env=e2.3
  void                    Deopt              !v    %33.1, DeadCall@0x55555700c608[Call#4], %33.0   !
BB32   <- [31]
  goto BB8
BB14   <- [12]
  val?^ | miss    %14.0 = LdVar              eR    as.name, R_GlobalEnv
  lgl$#-          %14.1 = Identical                %14.0, function(x) <(rir::DispatchTable*)0x555557b7ea|...
  void                    Assume             D     %14.1, %12.5 (CallTarget@0x555557c41840[Call#11])
  val?^ | miss    %14.3 = LdVar              eR    as.character, R_GlobalEnv
  lgl$#-          %14.4 = Identical                %14.3, <blt as.character>
  void                    Assume             D     %14.4, %12.5 (CallTarget@0x555557c41840[Call#12])
  (cls|spec|blt)  %14.6 = LdFun              !v    substitute, <0x555555a327a8>, R_GlobalEnv
  prom-           %14.7 = MkArg                    unboundValue, test[0x5555586a5dd0]_p20, e12.3
  val?            %14.8 = Call               !v    %14.6(%14.7) e12.3   <sym->
  val?            %14.9 = CallBuiltin        !v    as.character(%14.8) e12.3   <str$->
  lgl$#-          %14.10 = IsType                   %14.9 isA val?-
  cp              %14.11 = Checkpoint                -> BB16 (default) | BB15 (if assume failed)
BB13   <- [12]
  fs              %13.0 = FrameState         R     0x555555bc41e0+364: [], env=e2.3
  fs              %13.1 = FrameState         R     0x555557b5b4c0+474: [<blt .Call>, "pirCompileWrapper", %12.4], env=e12.3, next=%13.0
  void                    Deopt              !v    %13.1   !
BB16   <- [14]
  void                    Assume             D     %14.10, %14.11 (Typecheck@0x555556fd6d08[Type#0])
  val?-           %16.1 = CastType           d     dn %14.9   <str$->
  val             %16.2 = CallSafeBuiltin    wed   as.vector(%16.1, "symbol")    <sym->
  val?^ | miss    %16.3 = LdVar              eR    debugFlags, e12.3
  val?            %16.4 = Force!<value>      !v    %16.3, e12.3   <nil->
  val?^ | miss    %16.5 = LdVar              eR    debugStyle, e12.3
  val?            %16.6 = Force!<value>      !v    %16.5, e12.3   <nil->
  val?            %16.7 = CallBuiltin        !v    .Call("pirCompileWrapper", %12.4, %16.2, %16.4, %16.6) e12.3   <cls->
  val?            %16.8 = PopContext         C     %16.7, %10.4   <cls->
  void                    StVar              lW    f, %16.8, e2.3
  (cls|spec|blt)  %16.10 = LdFun              !v    f, <%16.8>, e2.3
  val?            %16.11 = Call               !v    %16.10() e2.3   <val?$->
  void                    StVar              lW    res, %16.11, e2.3
  cp              %16.13 = Checkpoint                -> BB18 (default) | BB17 (if assume failed)
BB15   <- [14]
  fs              %15.0 = FrameState         R     0x555555bc41e0+364: [], env=e2.3
  fs              %15.1 = FrameState         R     0x555557b5b4c0+511: [<blt .Call>, "pirCompileWrapper", %12.4], env=e12.3, next=%15.0
  prom-           %15.2 = MkArg                    unboundValue, test[0x5555586a5dd0]_p18, e12.3
  val?^           %15.3 = CastType                 up %15.2
  env             e15.4 = (MkEnv)            l     x=%15.3, parent=R_BaseNamespace, context 0
  fs              %15.5 = FrameState         R     0x555555cf17f0+9: [], env=e15.4, next=%15.1
  fs              %15.6 = FrameState         R     0x555557c22500+32(pr): [%14.9], env=e12.3, next=%15.5
  void                    Deopt              !v    %15.6   !
BB18   <- [16]
  val?^ | miss    %18.0 = LdVar              eR    paste, e2.3
  lgl$#-          %18.1 = Identical                %18.0, function(..., sep=" ", collapse=NULL, recycle0|...
  void                    Assume             D     %18.1, %16.13 (CallTarget@0x55555700c608[Call#11])
  prom-           %18.3 = MkArg                    unboundValue, test[0x5555586a5dd0]_p2 (!refl), e2.3
  prom-           %18.4 = MkArg                    unboundValue, test[0x5555586a5dd0]_p3, e2.3
  dots-           %18.5 = DotsList           l     %18.3, %18.4
  val?^ | miss    %18.6 = CastType                 up %18.3
  val?^ | miss    %18.7 = CastType                 up %18.4
  env             e18.8 = MkEnv              l     ...=%18.5, sep(miss)=" ", collapse(miss)=nil, recycle0(miss)=false, parent=R_BaseNamespace, context 0
  val?            %18.9 = Force!             !vrL  %18.6, e18.8
  val?            %18.10 = Force!             !vL   %18.7, e18.8
  val+            %18.11 = CallSafeBuiltin    wed   list(%18.9, %18.10)    <vec->
  val+            %18.12 = CallSafeBuiltin    wed   paste(%18.11, " ", nil, false)    <str$->
  val?^ | miss    %18.13 = LdVar              eR    expected, e2.3
  val?            %18.14 = Force!<wrapped>    !v    %18.13, e2.3   <str$->
  lgl$#-          %18.15 = IsType                   %18.14 isA val?-
  lgl$#-          %18.16 = IsType                   %18.12 isA val?-
  cp              %18.17 = Checkpoint                -> BB20 (default) | BB19 (if assume failed)
BB17   <- [16]
  fs              %17.0 = FrameState         R     0x555555bc41e0+419: [], env=e2.3
  void                    Deopt              !v    %17.0   !
BB20   <- [18]
  void                    Assume             D     %18.16, %18.17 (Typecheck@0x55555700c608[Type#20])
  val-            %20.1 = CastType           d     dn %18.12   <str$->
  void                    Assume             D     %18.15, %18.17 (Typecheck@0x55555700c608[Type#21])
  val?-           %20.3 = CastType           d     dn %18.14   <str$->
  lgl-            %20.4 = Neq                wed   %20.1, %20.3, elided   <lgl$->
  lgl$#-          %20.5 = IsType                   %20.4 isA lgl$-
  cp              %20.6 = Checkpoint                -> BB22 (default) | BB21 (if assume failed)
BB19   <- [18]
  fs              %19.0 = FrameState         R     0x555555bc41e0+470: [%18.12, %18.14], env=e2.3
  void                    Deopt              !v    %19.0   !
BB22   <- [20]
  void                    Assume             D     %20.5, %20.6 (Typecheck@0x55555700c608[Type#22])
  lgl$-           %22.1 = CastType           d     dn %20.4
  lgl$#-          %22.2 = CheckTrueFalse     e     %22.1
  void                    Branch                   %22.2 -> BB24 (if true) | BB23 (if false)
BB21   <- [20]
  fs              %21.0 = FrameState         R     0x555555bc41e0+476: [%20.4], env=e2.3
  void                    Deopt              !v    %21.0   !
BB24   <- [22]
  (cls|spec|blt)  %24.0 = LdFun              !v    stop, e2.3
  fs              %24.1 = FrameState         R     0x555555bc41e0+503: [%24.0], env=e2.3
  void                    Deopt              !v    %24.1, DeadCall@0x55555700c608[Call#13], %24.0   !
BB23   <- [22]
  void                    Invisible          v     
  void                    Return             l     nil
Prom 0:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    f, e1.0
  void                    Visible            v     
  val?            %1.3  = Force<lazy>        !     %1.1, e1.0   <cls->
  void                    Return             l     %1.3
Prom 1:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    f, e1.0
  void                    Visible            v     
  val?            %1.3  = Force<value>       !     %1.1, e1.0   <cls->
  void                    Return             l     %1.3
Prom 2:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    res, e1.0
  void                    Visible            v     
  val?            %1.3  = Force<value>       !     %1.1, e1.0   <val?$->
  void                    Return             l     %1.3
Prom 3:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  (cls|spec|blt)  %1.1  = LdFun              !     typeof, <0x555557b25810>, e1.0
  prom-           %1.2  = MkArg                    unboundValue, test[0x5555586a5dd0]_p4, e1.0
  val?            %1.3  = Call               !     %1.1(%1.2) e1.0   <str$->
  void                    Return             l     %1.3
Prom 4:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    res, e1.0
  void                    Visible            v     
  val?            %1.3  = Force<value>       !     %1.1, e1.0   <val?$->
  void                    Return             l     %1.3
Prom 5:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    res, e1.0
  void                    Visible            v     
  val?            %1.3  = Force<value>       !     %1.1, e1.0   <val?$->
  void                    Return             l     %1.3
Prom 6:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  (cls|spec|blt)  %1.1  = LdFun              !     typeof, <0x555557b25810>, e1.0
  prom-           %1.2  = MkArg                    unboundValue, test[0x5555586a5dd0]_p7, e1.0
  val?            %1.3  = Call               !     %1.1(%1.2) e1.0   <str$->
  void                    Return             l     %1.3
Prom 7:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    res, e1.0
  void                    Visible            v     
  val?            %1.3  = Force<value>       !     %1.1, e1.0   <val?$->
  void                    Return             l     %1.3
Prom 18:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  (cls|spec|blt)  %1.1  = LdFun              !     as.character, <0x555555a40380>, e1.0
  prom-           %1.2  = MkArg                    unboundValue, test[0x5555586a5dd0]_p19, e1.0
  val?            %1.3  = Call               !     %1.1(%1.2) e1.0   <str$->
  void                    Return             l     %1.3
Prom 19:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  (cls|spec|blt)  %1.1  = LdFun              !     substitute, <0x555555a327a8>, e1.0
  prom-           %1.2  = MkArg                    unboundValue, test[0x5555586a5dd0]_p20, e1.0
  val?            %1.3  = Call               !     %1.1(%1.2) e1.0   <sym->
  void                    Return             l     %1.3
Prom 20:
BB0
  goto BB1
BB1   <- [0]
  env             e1.0  = LdFunctionEnv            
  val?^ | miss    %1.1  = LdVar              eR    what, e1.0
  void                    Visible            v     
  val?            %1.3  = Force              !     %1.1, e1.0   <val?_>
  void                    Return             l     %1.3

│ test[0x5555586a5dd0]                                                         │
└──────────────────────────────────────────────────────────────────────────────┘

Deopt log:

DEOPT, assumption
val?^           %1.1  = LdArg                    0
val?~+          %1.0  = LdArg                    1
env             e35.0 = MkEnv              l     f=%1.1, expected=%1.0, parent=R_GlobalEnv, context 1
val?^ | miss    %27.0 = LdVar              eR    paste, e35.0
lgl$#-          %27.1 = Identical                %27.0, function(..., sep=" ", collapse=NULL, recycle0|...

 failed
DEOPT:
env             e35.0 = MkEnv              l     f=%1.1, expected=%1.0, parent=R_GlobalEnv, context 1
fs              %26.2 = FrameState         R     0x555555bc41e0+112: [], env=e35.0
dr              %26.1 = Phi                      CallTarget@0x55555700c608[Call#2]:BB42
val?^ | miss    %27.0 = LdVar              eR    paste, e35.0
val?^ | miss    %26.0 = Phi                      %27.0:BB42
void                    Deopt              !v    %26.2, %26.1, %26.0   !
@rihafilip rihafilip added the bug label Jun 27, 2024
@skrynski skrynski self-assigned this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants