Skip to content

LLVM miscompiles trivial switch for AArch64 #3271

@LemonBoy

Description

@LemonBoy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-aarch6464-bit ArmbugObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.upstreamAn issue with a third party project that Zig uses.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions