Skip to content

Commit 50cf413

Browse files
committed
[X86,CodeGen] Return the correct condition code for SETZUCC
llvm-issue: #101288
1 parent 1961f9f commit 50cf413

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,9 +3121,9 @@ bool X86InstrInfo::hasCommutePreference(MachineInstr &MI, bool &Commute) const {
31213121

31223122
int X86::getCondSrcNoFromDesc(const MCInstrDesc &MCID) {
31233123
unsigned Opcode = MCID.getOpcode();
3124-
if (!(X86::isJCC(Opcode) || X86::isSETCC(Opcode) || X86::isCMOVCC(Opcode) ||
3125-
X86::isCFCMOVCC(Opcode) || X86::isCCMPCC(Opcode) ||
3126-
X86::isCTESTCC(Opcode)))
3124+
if (!(X86::isJCC(Opcode) || X86::isSETCC(Opcode) || X86::isSETZUCC(Opcode) ||
3125+
X86::isCMOVCC(Opcode) || X86::isCFCMOVCC(Opcode) ||
3126+
X86::isCCMPCC(Opcode) || X86::isCTESTCC(Opcode)))
31273127
return -1;
31283128
// Assume that condition code is always the last use operand.
31293129
unsigned NumUses = MCID.getNumOperands() - MCID.getNumDefs();
@@ -3145,8 +3145,9 @@ X86::CondCode X86::getCondFromBranch(const MachineInstr &MI) {
31453145
}
31463146

31473147
X86::CondCode X86::getCondFromSETCC(const MachineInstr &MI) {
3148-
return X86::isSETCC(MI.getOpcode()) ? X86::getCondFromMI(MI)
3149-
: X86::COND_INVALID;
3148+
return X86::isSETCC(MI.getOpcode()) || X86::isSETZUCC(MI.getOpcode())
3149+
? X86::getCondFromMI(MI)
3150+
: X86::COND_INVALID;
31503151
}
31513152

31523153
X86::CondCode X86::getCondFromCMov(const MachineInstr &MI) {

llvm/test/CodeGen/X86/apx/setzucc.ll

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,46 @@ define i64 @i64(i64 %x) nounwind {
4646
%if = select i1 %t0, i64 1, i64 0
4747
ret i64 %if
4848
}
49+
50+
define i32 @flags_copy_lowering() nounwind {
51+
; CHECK-LABEL: flags_copy_lowering:
52+
; CHECK: # %bb.0: # %bb
53+
; CHECK-NEXT: xorl %eax, %eax
54+
; CHECK-NEXT: xorl %edx, %edx
55+
; CHECK-NEXT: xorl %ecx, %ecx
56+
; CHECK-NEXT: .p2align 4, 0x90
57+
; CHECK-NEXT: .LBB4_1: # %bb1
58+
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
59+
; CHECK-NEXT: addl %edx, 0
60+
; CHECK-NEXT: setb %sil
61+
; CHECK-NEXT: adcl $0, %ecx
62+
; CHECK-NEXT: testb %sil, %sil
63+
; CHECK-NEXT: setzune %dl
64+
; CHECK-NEXT: testb %sil, %sil
65+
; CHECK-NEXT: je .LBB4_3
66+
; CHECK-NEXT: # %bb.2: # %bb1
67+
; CHECK-NEXT: # in Loop: Header=BB4_1 Depth=1
68+
; CHECK-NEXT: testb %al, %al
69+
; CHECK-NEXT: jne .LBB4_1
70+
; CHECK-NEXT: .LBB4_3: # %bb2
71+
; CHECK-NEXT: xorl %eax, %eax
72+
; CHECK-NEXT: retq
73+
bb:
74+
br label %bb1
75+
76+
bb1:
77+
%phi = phi i32 [ 0, %bb ], [ %zext, %bb1 ]
78+
%phi2 = phi i32 [ 0, %bb ], [ %add3, %bb1 ]
79+
%load = load i32, ptr null, align 4
80+
%add = add i32 %load, %phi
81+
store i32 %add, ptr null, align 4
82+
%icmp = icmp ugt i32 %phi, %add
83+
%zext = zext i1 %icmp to i32
84+
%add3 = add i32 %phi2, %zext
85+
%icmp4 = icmp ult i32 %phi2, 0
86+
%and = and i1 %icmp, false
87+
br i1 %and, label %bb1, label %bb2
88+
89+
bb2:
90+
ret i32 0
91+
}

0 commit comments

Comments
 (0)