Skip to content

Commit

Permalink
[X86] Pre-commit test case showing bug in combineOr (X86ISelLowering.…
Browse files Browse the repository at this point in the history
…cpp)

In combineOr (X86ISelLowering.cpp) there is a DAG combine that rewrite
a "(0 - SetCC) | C" pattern into something simpler given that a LEA
can be used. Another requirement is that C has some specific value,
for example 1 or 7. When doing that check it is using a 32-bit
unsigned variable to store the value of C. So for a 64-bit OR this
could miscompile in case any of the 32 most significant bits in C
are set.

This patch adds a test case to show this miscompile bug.

Differential Revision: https://reviews.llvm.org/D134890
  • Loading branch information
bjope committed Sep 29, 2022
1 parent 3a79f1c commit e4fcbf3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions llvm/test/CodeGen/X86/or-lea.ll
Original file line number Diff line number Diff line change
Expand Up @@ -792,3 +792,34 @@ define i64 @or_sext8_64(i64 %x) {
%or = or i64 %sext, 8
ret i64 %or
}

define i64 @or_large_constant(i64 %x) {
; X86-LABEL: or_large_constant:
; X86: # %bb.0: # %entry
; X86-NEXT: xorl %edx, %edx
; X86-NEXT: movl $1, %eax
; X86-NEXT: cmpl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl $0, %eax
; X86-NEXT: sbbl {{[0-9]+}}(%esp), %eax
; X86-NEXT: setl %al
; X86-NEXT: movzbl %al, %eax
; X86-NEXT: negl %eax
; X86-NEXT: sbbl %edx, %edx
; X86-NEXT: orl $1, %eax
; X86-NEXT: orl $128, %edx
; X86-NEXT: retl
;
; X64-LABEL: or_large_constant:
; X64: # %bb.0: # %entry
; X64-NEXT: xorl %eax, %eax
; X64-NEXT: cmpq $2, %rdi
; X64-NEXT: setl %al
; X64-NEXT: leaq -1(%rax,%rax), %rax
; X64-NEXT: retq
entry:
%cmp = icmp sgt i64 %x, 1
%zext = zext i1 %cmp to i64
%sub = sub i64 0, %zext
%or = or i64 %sub, 549755813889 ; 0x8000000001
ret i64 %or
}

0 comments on commit e4fcbf3

Please sign in to comment.