Skip to content

Commit cb10232

Browse files
committed
[X86][GlobalISel] Set Dst register correctly when narrowing G_ICMP
Due to untested branch in #119335 Fixes #167326
1 parent 346f48e commit cb10232

File tree

3 files changed

+174
-7
lines changed

3 files changed

+174
-7
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ LegalizerHelper::LegalizeResult LegalizerHelper::narrowScalar(MachineInstr &MI,
19301930
Register CmpOut;
19311931
CmpInst::Predicate PartPred;
19321932

1933-
if (I == E - 1 && LHSLeftoverRegs.empty()) {
1933+
if (I == E - 1) {
19341934
PartPred = Pred;
19351935
CmpOut = Dst;
19361936
} else {

llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
269269
getActionDefinitionsBuilder(G_ICMP)
270270
.legalForCartesianProduct({s8}, Is64Bit ? IntTypes64 : IntTypes32)
271271
.clampScalar(0, s8, s8)
272+
.widenScalarToNextPow2(1, /*Min=*/8)
272273
.clampScalar(1, s8, sMaxScalar);
273274

274275
// bswap

llvm/test/CodeGen/X86/isel-icmp.ll

Lines changed: 172 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -verify-machineinstrs | FileCheck %s --check-prefix=SDAG-X64
3-
; RUN: llc < %s -fast-isel -fast-isel-abort=1 -mtriple=x86_64-apple-darwin10 -verify-machineinstrs | FileCheck %s --check-prefix=FAST-X64
4-
; RUN: llc < %s -global-isel -global-isel-abort=1 -mtriple=x86_64-apple-darwin10 -verify-machineinstrs | FileCheck %s --check-prefixes=GISEL-X64
5-
; RUN: llc < %s -mtriple=i686-apple-darwin10 -verify-machineinstrs | FileCheck %s --check-prefixes=SDAG-X86
2+
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 | FileCheck %s --check-prefix=SDAG-X64
3+
; Allow fast-isel to fallback to selection dag on x86 for i96 type.
4+
; RUN: llc < %s -fast-isel -mtriple=x86_64-apple-darwin10 | FileCheck %s --check-prefix=FAST-X64
5+
; RUN: llc < %s -global-isel -global-isel-abort=1 -mtriple=x86_64-apple-darwin10 | FileCheck %s --check-prefixes=GISEL-X64
6+
; RUN: llc < %s -mtriple=i686-apple-darwin10 | FileCheck %s --check-prefixes=SDAG-X86
67
; Allow fast-isel to fallback to selection dag on x86
7-
; RUN: llc < %s -fast-isel -mtriple=i686-apple-darwin10 -verify-machineinstrs | FileCheck %s --check-prefixes=FAST-X86
8-
; RUN: llc < %s -global-isel -global-isel-abort=1 -mtriple=i686-apple-darwin10 -verify-machineinstrs | FileCheck %s --check-prefixes=GISEL-X86
8+
; RUN: llc < %s -fast-isel -mtriple=i686-apple-darwin10 | FileCheck %s --check-prefixes=FAST-X86
9+
; RUN: llc < %s -global-isel -global-isel-abort=1 -mtriple=i686-apple-darwin10 | FileCheck %s --check-prefixes=GISEL-X86
910

1011
define i32 @test_icmp_eq_i8(i8 %a, i8 %b) {
1112
; SDAG-X64-LABEL: test_icmp_eq_i8:
@@ -720,3 +721,168 @@ define i32 @test_icmp_sle_i32(i32 %a, i32 %b) {
720721
%res = zext i1 %r to i32
721722
ret i32 %res
722723
}
724+
725+
; PR167326
726+
define i32 @test_icmp_sge_i96(i96 %a, i96 %b) nounwind {
727+
; SDAG-X64-LABEL: test_icmp_sge_i96:
728+
; SDAG-X64: ## %bb.0:
729+
; SDAG-X64-NEXT: movslq %ecx, %rax
730+
; SDAG-X64-NEXT: movslq %esi, %rcx
731+
; SDAG-X64-NEXT: cmpq %rdx, %rdi
732+
; SDAG-X64-NEXT: sbbq %rax, %rcx
733+
; SDAG-X64-NEXT: setge %al
734+
; SDAG-X64-NEXT: movzbl %al, %eax
735+
; SDAG-X64-NEXT: retq
736+
;
737+
; FAST-X64-LABEL: test_icmp_sge_i96:
738+
; FAST-X64: ## %bb.0:
739+
; FAST-X64-NEXT: movslq %ecx, %rax
740+
; FAST-X64-NEXT: movslq %esi, %rcx
741+
; FAST-X64-NEXT: cmpq %rdx, %rdi
742+
; FAST-X64-NEXT: sbbq %rax, %rcx
743+
; FAST-X64-NEXT: setge %al
744+
; FAST-X64-NEXT: andb $1, %al
745+
; FAST-X64-NEXT: movzbl %al, %eax
746+
; FAST-X64-NEXT: retq
747+
;
748+
; GISEL-X64-LABEL: test_icmp_sge_i96:
749+
; GISEL-X64: ## %bb.0:
750+
; GISEL-X64-NEXT: movq %rcx, %rax
751+
; GISEL-X64-NEXT: movq %rdi, %r8
752+
; GISEL-X64-NEXT: movb $32, %cl
753+
; GISEL-X64-NEXT: shlq %cl, %r8
754+
; GISEL-X64-NEXT: shlq %cl, %rsi
755+
; GISEL-X64-NEXT: shrq %cl, %rdi
756+
; GISEL-X64-NEXT: orq %rsi, %rdi
757+
; GISEL-X64-NEXT: shrq %cl, %r8
758+
; GISEL-X64-NEXT: movq %rdi, %rsi
759+
; GISEL-X64-NEXT: shlq %cl, %rsi
760+
; GISEL-X64-NEXT: orq %r8, %rsi
761+
; GISEL-X64-NEXT: sarq %cl, %rdi
762+
; GISEL-X64-NEXT: movq %rdx, %rcx
763+
; GISEL-X64-NEXT: shlq $32, %rcx
764+
; GISEL-X64-NEXT: shlq $32, %rax
765+
; GISEL-X64-NEXT: shrq $32, %rdx
766+
; GISEL-X64-NEXT: orq %rax, %rdx
767+
; GISEL-X64-NEXT: shrq $32, %rcx
768+
; GISEL-X64-NEXT: movq %rdx, %rax
769+
; GISEL-X64-NEXT: shlq $32, %rax
770+
; GISEL-X64-NEXT: orq %rcx, %rax
771+
; GISEL-X64-NEXT: sarq $32, %rdx
772+
; GISEL-X64-NEXT: xorl %ecx, %ecx
773+
; GISEL-X64-NEXT: cmpq %rax, %rsi
774+
; GISEL-X64-NEXT: setae %cl
775+
; GISEL-X64-NEXT: xorl %eax, %eax
776+
; GISEL-X64-NEXT: xorl %esi, %esi
777+
; GISEL-X64-NEXT: cmpq %rdx, %rdi
778+
; GISEL-X64-NEXT: setge %al
779+
; GISEL-X64-NEXT: sete %sil
780+
; GISEL-X64-NEXT: testl %esi, %esi
781+
; GISEL-X64-NEXT: cmovnew %cx, %ax
782+
; GISEL-X64-NEXT: andl $1, %eax
783+
; GISEL-X64-NEXT: retq
784+
;
785+
; SDAG-X86-LABEL: test_icmp_sge_i96:
786+
; SDAG-X86: ## %bb.0:
787+
; SDAG-X86-NEXT: pushl %ebx
788+
; SDAG-X86-NEXT: pushl %edi
789+
; SDAG-X86-NEXT: pushl %esi
790+
; SDAG-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
791+
; SDAG-X86-NEXT: movl %eax, %ecx
792+
; SDAG-X86-NEXT: sarl $31, %ecx
793+
; SDAG-X86-NEXT: movl {{[0-9]+}}(%esp), %edx
794+
; SDAG-X86-NEXT: movl %edx, %esi
795+
; SDAG-X86-NEXT: sarl $31, %esi
796+
; SDAG-X86-NEXT: movl {{[0-9]+}}(%esp), %edi
797+
; SDAG-X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
798+
; SDAG-X86-NEXT: cmpl {{[0-9]+}}(%esp), %edi
799+
; SDAG-X86-NEXT: sbbl {{[0-9]+}}(%esp), %ebx
800+
; SDAG-X86-NEXT: sbbl %eax, %edx
801+
; SDAG-X86-NEXT: sbbl %ecx, %esi
802+
; SDAG-X86-NEXT: setge %al
803+
; SDAG-X86-NEXT: movzbl %al, %eax
804+
; SDAG-X86-NEXT: popl %esi
805+
; SDAG-X86-NEXT: popl %edi
806+
; SDAG-X86-NEXT: popl %ebx
807+
; SDAG-X86-NEXT: retl
808+
;
809+
; FAST-X86-LABEL: test_icmp_sge_i96:
810+
; FAST-X86: ## %bb.0:
811+
; FAST-X86-NEXT: pushl %ebx
812+
; FAST-X86-NEXT: pushl %edi
813+
; FAST-X86-NEXT: pushl %esi
814+
; FAST-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
815+
; FAST-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
816+
; FAST-X86-NEXT: movl {{[0-9]+}}(%esp), %edx
817+
; FAST-X86-NEXT: movl {{[0-9]+}}(%esp), %esi
818+
; FAST-X86-NEXT: movl %eax, %edi
819+
; FAST-X86-NEXT: sarl $31, %edi
820+
; FAST-X86-NEXT: movl %edx, %ebx
821+
; FAST-X86-NEXT: sarl $31, %ebx
822+
; FAST-X86-NEXT: cmpl %ecx, {{[0-9]+}}(%esp)
823+
; FAST-X86-NEXT: sbbl {{[0-9]+}}(%esp), %esi
824+
; FAST-X86-NEXT: sbbl %eax, %edx
825+
; FAST-X86-NEXT: sbbl %edi, %ebx
826+
; FAST-X86-NEXT: setge %al
827+
; FAST-X86-NEXT: andb $1, %al
828+
; FAST-X86-NEXT: movzbl %al, %eax
829+
; FAST-X86-NEXT: popl %esi
830+
; FAST-X86-NEXT: popl %edi
831+
; FAST-X86-NEXT: popl %ebx
832+
; FAST-X86-NEXT: retl
833+
;
834+
; GISEL-X86-LABEL: test_icmp_sge_i96:
835+
; GISEL-X86: ## %bb.0:
836+
; GISEL-X86-NEXT: pushl %ebp
837+
; GISEL-X86-NEXT: pushl %ebx
838+
; GISEL-X86-NEXT: pushl %edi
839+
; GISEL-X86-NEXT: pushl %esi
840+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %edx
841+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %edi
842+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
843+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %esi
844+
; GISEL-X86-NEXT: movl %edx, %eax
845+
; GISEL-X86-NEXT: movb $31, %cl
846+
; GISEL-X86-NEXT: sarl %cl, %eax
847+
; GISEL-X86-NEXT: cmpl %edi, {{[0-9]+}}(%esp)
848+
; GISEL-X86-NEXT: setae %ch
849+
; GISEL-X86-NEXT: xorl %ebx, %ebx
850+
; GISEL-X86-NEXT: cmpl %ebp, {{[0-9]+}}(%esp)
851+
; GISEL-X86-NEXT: setae %cl
852+
; GISEL-X86-NEXT: sete %bl
853+
; GISEL-X86-NEXT: testl %ebx, %ebx
854+
; GISEL-X86-NEXT: je LBB13_2
855+
; GISEL-X86-NEXT: ## %bb.1:
856+
; GISEL-X86-NEXT: movb %ch, %cl
857+
; GISEL-X86-NEXT: LBB13_2:
858+
; GISEL-X86-NEXT: movl %esi, %edi
859+
; GISEL-X86-NEXT: sarl $31, %edi
860+
; GISEL-X86-NEXT: xorl %ebx, %ebx
861+
; GISEL-X86-NEXT: cmpl %esi, %edx
862+
; GISEL-X86-NEXT: setae %dl
863+
; GISEL-X86-NEXT: sete %bl
864+
; GISEL-X86-NEXT: testl %ebx, %ebx
865+
; GISEL-X86-NEXT: je LBB13_4
866+
; GISEL-X86-NEXT: ## %bb.3:
867+
; GISEL-X86-NEXT: movl %ecx, %edx
868+
; GISEL-X86-NEXT: LBB13_4:
869+
; GISEL-X86-NEXT: xorl %ecx, %ecx
870+
; GISEL-X86-NEXT: cmpl %edi, %eax
871+
; GISEL-X86-NEXT: setge %al
872+
; GISEL-X86-NEXT: sete %cl
873+
; GISEL-X86-NEXT: testl %ecx, %ecx
874+
; GISEL-X86-NEXT: je LBB13_6
875+
; GISEL-X86-NEXT: ## %bb.5:
876+
; GISEL-X86-NEXT: movl %edx, %eax
877+
; GISEL-X86-NEXT: LBB13_6:
878+
; GISEL-X86-NEXT: movzbl %al, %eax
879+
; GISEL-X86-NEXT: andl $1, %eax
880+
; GISEL-X86-NEXT: popl %esi
881+
; GISEL-X86-NEXT: popl %edi
882+
; GISEL-X86-NEXT: popl %ebx
883+
; GISEL-X86-NEXT: popl %ebp
884+
; GISEL-X86-NEXT: retl
885+
%r = icmp sge i96 %a, %b
886+
%res = zext i1 %r to i32
887+
ret i32 %res
888+
}

0 commit comments

Comments
 (0)