Skip to content

Commit 1c4bc9b

Browse files
committed
Address review comments
1 parent 3f0314d commit 1c4bc9b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5352,12 +5352,12 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
53525352
MachineInstr *MI = nullptr;
53535353
MachineInstr *Sub = nullptr;
53545354
MachineInstr *Movr0Inst = nullptr;
5355-
SmallVector<MachineInstr *, 4> NDDInsts;
5355+
SmallVector<std::pair<MachineInstr *, unsigned>, 4> InstsToUpdate;
53565356
bool NoSignFlag = false;
53575357
bool ClearsOverflowFlag = false;
53585358
bool ShouldUpdateCC = false;
53595359
bool IsSwapped = false;
5360-
bool HasCF = Subtarget.hasNF();
5360+
bool HasNF = Subtarget.hasNF();
53615361
unsigned OpNo = 0;
53625362
X86::CondCode NewCC = X86::COND_INVALID;
53635363
int64_t ImmDelta = 0;
@@ -5443,10 +5443,13 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
54435443
continue;
54445444
}
54455445

5446-
// Try to replace NDD with NF instructions.
5447-
if (HasCF && X86II::hasNewDataDest(Inst.getDesc().TSFlags) &&
5448-
Inst.registerDefIsDead(X86::EFLAGS, TRI)) {
5449-
NDDInsts.push_back(&Inst);
5446+
// Try to replace non-NF with NF instructions.
5447+
if (HasNF && Inst.registerDefIsDead(X86::EFLAGS, TRI)) {
5448+
unsigned NewOp = X86::getNFVariant(Inst.getOpcode());
5449+
if (!NewOp)
5450+
return false;
5451+
5452+
InstsToUpdate.push_back(std::make_pair(&Inst, NewOp));
54505453
continue;
54515454
}
54525455

@@ -5646,10 +5649,10 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
56465649
return false;
56475650
}
56485651

5649-
// Replace NDD with NF instructions.
5650-
for (MachineInstr *NDD : NDDInsts) {
5651-
NDD->setDesc(get(X86::getNFVariant(NDD->getOpcode())));
5652-
NDD->removeOperand(NDD->getNumOperands() - 1);
5652+
// Replace non-NF with NF instructions.
5653+
for (auto &Inst : InstsToUpdate) {
5654+
Inst.first->setDesc(get(Inst.second));
5655+
Inst.first->removeOperand(Inst.first->getNumOperands() - 1);
56535656
}
56545657

56555658
// Make sure Sub instruction defines EFLAGS and mark the def live.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc < %s -mtriple=x86_64 -mattr=+cf,+nf,+ndd,+avx512f -verify-machineinstrs | FileCheck %s
2+
; RUN: llc < %s -mtriple=x86_64 -mattr=+cf,+nf,+avx512f -verify-machineinstrs | FileCheck %s
33

44
define void @basic(i32 %a, ptr %b, ptr %p, ptr %q) {
55
; CHECK-LABEL: basic:
@@ -57,8 +57,9 @@ entry:
5757
define i64 @reduced_data_dependency(i64 %a, i64 %b, ptr %c) {
5858
; CHECK-LABEL: reduced_data_dependency:
5959
; CHECK: # %bb.0: # %entry
60-
; CHECK-NEXT: subq %rsi, %rdi, %rax
61-
; CHECK-NEXT: cfcmovnsq (%rdx), %rdi, %rcx
60+
; CHECK-NEXT: movq %rdi, %rcx
61+
; CHECK-NEXT: subq %rsi, %rcx
62+
; CHECK-NEXT: cfcmovnsq (%rdx), %rdi, %rax
6263
; CHECK-NEXT: addq %rcx, %rax
6364
; CHECK-NEXT: retq
6465
entry:
@@ -144,7 +145,7 @@ define void @load_add_store(i32 %a, i32 %b, ptr %p) {
144145
; CHECK: # %bb.0: # %entry
145146
; CHECK-NEXT: cmpl %esi, %edi
146147
; CHECK-NEXT: cfcmovnew (%rdx), %ax
147-
; CHECK-NEXT: {nf} incw %ax
148+
; CHECK-NEXT: {nf} incl %eax
148149
; CHECK-NEXT: cfcmovnew %ax, (%rdx)
149150
; CHECK-NEXT: retq
150151
entry:

0 commit comments

Comments
 (0)