Skip to content

Commit 5fd9bbd

Browse files
committed
[DAGCombiner] Pre-commit test case for miscompile bug in combineShiftOfShiftedLogic
DAGCombiner is trying to fold shl over binops, and in the process combining it with another shl. However it needs to be more careful to ensure that the sum of the shift counts fits in the type used for the shift amount. For example, X86 is using i8 as shift amount type. So we need to make sure that the sum of the shift amounts isn't greater than 255. Fix will be applied in a later commit. This only pre-commits the test case to show that we currently get the wrong result. Bug was found when testing the C23 BitInt feature.
1 parent 0661af8 commit 5fd9bbd

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Diff for: llvm/test/CodeGen/X86/shift-combine.ll

+65
Original file line numberDiff line numberDiff line change
@@ -787,3 +787,68 @@ define <4 x i32> @or_tree_with_mismatching_shifts_vec_i32(<4 x i32> %a, <4 x i32
787787
%r = or <4 x i32> %or.ab, %or.cd
788788
ret <4 x i32> %r
789789
}
790+
791+
; FIXME: Reproducer for a DAGCombiner::combineShiftOfShiftedLogic
792+
; bug. DAGCombiner need to check that the sum of the shift amounts fits in i8,
793+
; which is the legal type used to described X86 shift amounts. Verify that we
794+
; do not try to create a shift with 130+160 as shift amount, and verify that
795+
; the stored value do not depend on %a1.
796+
define void @combineShiftOfShiftedLogic(i128 %a1, i32 %a2, ptr %p) {
797+
; X86-LABEL: combineShiftOfShiftedLogic:
798+
; X86: # %bb.0:
799+
; X86-NEXT: pushl %ebx
800+
; X86-NEXT: .cfi_def_cfa_offset 8
801+
; X86-NEXT: pushl %edi
802+
; X86-NEXT: .cfi_def_cfa_offset 12
803+
; X86-NEXT: pushl %esi
804+
; X86-NEXT: .cfi_def_cfa_offset 16
805+
; X86-NEXT: .cfi_offset %esi, -16
806+
; X86-NEXT: .cfi_offset %edi, -12
807+
; X86-NEXT: .cfi_offset %ebx, -8
808+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
809+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
810+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
811+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
812+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
813+
; X86-NEXT: movl %edi, %esi
814+
; X86-NEXT: shldl $2, %ebx, %edi
815+
; X86-NEXT: shldl $2, %edx, %ebx
816+
; X86-NEXT: shrl $30, %esi
817+
; X86-NEXT: orl {{[0-9]+}}(%esp), %esi
818+
; X86-NEXT: shldl $2, %ecx, %edx
819+
; X86-NEXT: shll $2, %ecx
820+
; X86-NEXT: movl %edi, 16(%eax)
821+
; X86-NEXT: movl %ebx, 12(%eax)
822+
; X86-NEXT: movl %edx, 8(%eax)
823+
; X86-NEXT: movl %ecx, 4(%eax)
824+
; X86-NEXT: movl %esi, 20(%eax)
825+
; X86-NEXT: movl $0, (%eax)
826+
; X86-NEXT: popl %esi
827+
; X86-NEXT: .cfi_def_cfa_offset 12
828+
; X86-NEXT: popl %edi
829+
; X86-NEXT: .cfi_def_cfa_offset 8
830+
; X86-NEXT: popl %ebx
831+
; X86-NEXT: .cfi_def_cfa_offset 4
832+
; X86-NEXT: retl
833+
;
834+
; X64-LABEL: combineShiftOfShiftedLogic:
835+
; X64: # %bb.0:
836+
; X64-NEXT: # kill: def $edx killed $edx def $rdx
837+
; X64-NEXT: shlq $32, %rdx
838+
; X64-NEXT: movq %rsi, %rax
839+
; X64-NEXT: shrq $30, %rax
840+
; X64-NEXT: orq %rdx, %rax
841+
; X64-NEXT: shldq $34, %rdi, %rsi
842+
; X64-NEXT: shlq $34, %rdi
843+
; X64-NEXT: movq %rsi, 8(%rcx)
844+
; X64-NEXT: movq %rdi, (%rcx)
845+
; X64-NEXT: movq %rax, 16(%rcx)
846+
; X64-NEXT: retq
847+
%zext1 = zext i128 %a1 to i192
848+
%zext2 = zext i32 %a2 to i192
849+
%shl = shl i192 %zext1, 130
850+
%or = or i192 %shl, %zext2
851+
%res = shl i192 %or, 160
852+
store i192 %res, ptr %p, align 8
853+
ret void
854+
}

0 commit comments

Comments
 (0)