reactorlabs / rir

GNU General Public License v2.0
62 stars 18 forks source link

Wrong translation to PIR when calling c(1,2) #1280

Open skrynski opened 2 months ago

skrynski commented 2 months ago

Running the following snippet (without running f), produced the PIR code below. Notice we call the builtin c in both branches instead of LdFun

f <- function() {
    x <- c(1,2)
    x
}

rir.compile(f)
pir.compile(f)
┌──────────────────────────────────────────────────────────────────────────────┐                                                         
│ f[0x5645a8b596f0]                                                            │                                                         
│ Context: CorrOrd,!TMany                                                      │                                                         
│ Properties:  Eager, !Reflection                                              │                                                         
├────── PIR Version After Optimizations                                                                                                  
f[0x5645a8b596f0]                                                                                                                        
BB0                                                                                                                                      
  goto BB1                                                                                                                               
BB1   <- [0]                                                                                                                             
  val?^ | miss    %1.0  = LdVar              eR    c, R_GlobalEnv                                                                        
  lgl$#-          %1.1  = Identical                <blt c>, %1.0   <@?>                                                                  
  void                    Branch                   %1.1 -> BB2 (if true) | BB4 (if false)                                                
BB2   <- [1]                                                                                                                             
  real-           %2.0  = CallSafeBuiltin    wed   c(1, 2)                                                                               
  goto BB3                                                                                                                               
BB4   <- [1]                                                                                                                             
  **real-           %4.0  = CallSafeBuiltin    wed   c(1, 2)**                                                                               
  goto BB3                                                                                                                               
BB3   <- [2, 4]                                                                                                                          
  real-           %3.0  = Phi                      %4.0:BB4, %2.0:BB2   <val?_>                                                          
  void                    Visible            v                                                                                           
  void                    Return             l     %3.0                                                                                  

│ f[0x5645a8b596f0]                                                            │                                                         
└──────────────────────────────────────────────────────────────────────────────┘