Zig: LLVM miscompiles trivial switch for AArch64

Created on 20 Sep 2019  路  7Comments  路  Source: ziglang/zig

Here's the reduced llvm-ir test case:

; Function Attrs: cold nobuiltin noreturn nounwind                               
define internal void @bar() unnamed_addr #1 {                                    
    unreachable                                                                  
}                                                                                

define i1 @foo(i1) unnamed_addr #0 {                                             
Entry:                                                                           
  switch i1 %0, label %BadValue [                                                
    i1 false, label %OkValue                                                     
    i1 true, label %OkValue                                                      
  ]                                                                              

BadValue:                                                                        
  call fastcc void @bar()                                                        
  unreachable                                                                    

OkValue:                                                                           
  ret i1 %0                                                                      
}                            

LLVM9 generates nonsensical code:

    mov w8, #1                                                                   
    mov w9, w0                                                                     
    and w9, w9, w8                                                               
    mov w10, #0                                                                  
    and w8, w10, w8 // w8 is turned into zero     
    cmp w9, w8 // Comparison against zero
    str w0, [sp, #12]                 
    b.ls    .LBB1_2 // The branch is _never_ taken

Please report to the LLVM devs, I have no bugzilla account.

arch-arm64 bug miscompilation upstream

Most helpful comment

I've committed a fix in r372675. Please check it fixes your issue on the latest trunk build.

The fix is working as intended, the tests are now passing.

All 7 comments

Looks like it's going to be a release blocker for 9.0.1 :+1:

comment 7

I've committed a fix in r372675. Please check it fixes your issue on the latest trunk build.

I've committed a fix in r372675. Please check it fixes your issue on the latest trunk build.

The fix is working as intended, the tests are now passing.

The upstream fix is in the 9.0.1 release branch. I'll close this issue when LLVM 9.0.1 is released.

Fixed with the merge of llvm10 branch: 93c7fa105f9cc4dbb36192469ecff47102d955d6

Was this page helpful?
0 / 5 - 0 ratings