Skip to content

Commit 3b7668a

Browse files
committed
AMDGPU/GlobalISel: Improve icmp selection coverage.
Select s64 eq/ne scalar icmp. llvm-svn: 364765
1 parent 9f36458 commit 3b7668a

File tree

3 files changed

+633
-13
lines changed

3 files changed

+633
-13
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ bool AMDGPUInstructionSelector::selectG_INTRINSIC(MachineInstr &I,
317317
return false;
318318
}
319319

320-
static unsigned getV_CMPOpcode(CmpInst::Predicate P, unsigned Size) {
321-
assert(Size == 32 || Size == 64);
320+
static int getV_CMPOpcode(CmpInst::Predicate P, unsigned Size) {
321+
if (Size != 32 && Size != 64)
322+
return -1;
322323
switch (P) {
323324
default:
324325
llvm_unreachable("Unknown condition code!");
@@ -345,12 +346,26 @@ static unsigned getV_CMPOpcode(CmpInst::Predicate P, unsigned Size) {
345346
}
346347
}
347348

348-
static unsigned getS_CMPOpcode(CmpInst::Predicate P, unsigned Size) {
349-
// FIXME: VI supports 64-bit comparse.
350-
assert(Size == 32);
349+
int AMDGPUInstructionSelector::getS_CMPOpcode(CmpInst::Predicate P,
350+
unsigned Size) const {
351+
if (Size == 64) {
352+
if (!STI.hasScalarCompareEq64())
353+
return -1;
354+
355+
switch (P) {
356+
case CmpInst::ICMP_NE:
357+
return AMDGPU::S_CMP_LG_U64;
358+
case CmpInst::ICMP_EQ:
359+
return AMDGPU::S_CMP_EQ_U64;
360+
default:
361+
return -1;
362+
}
363+
}
364+
365+
if (Size != 32)
366+
return -1;
367+
351368
switch (P) {
352-
default:
353-
llvm_unreachable("Unknown condition code!");
354369
case CmpInst::ICMP_NE:
355370
return AMDGPU::S_CMP_LG_U32;
356371
case CmpInst::ICMP_EQ:
@@ -371,6 +386,8 @@ static unsigned getS_CMPOpcode(CmpInst::Predicate P, unsigned Size) {
371386
return AMDGPU::S_CMP_LT_U32;
372387
case CmpInst::ICMP_ULE:
373388
return AMDGPU::S_CMP_LE_U32;
389+
default:
390+
llvm_unreachable("Unknown condition code!");
374391
}
375392
}
376393

@@ -382,12 +399,14 @@ bool AMDGPUInstructionSelector::selectG_ICMP(MachineInstr &I) const {
382399

383400
unsigned SrcReg = I.getOperand(2).getReg();
384401
unsigned Size = RBI.getSizeInBits(SrcReg, MRI, TRI);
385-
// FIXME: VI supports 64-bit compares.
386-
assert(Size == 32);
402+
403+
auto Pred = (CmpInst::Predicate)I.getOperand(1).getPredicate();
387404

388405
unsigned CCReg = I.getOperand(0).getReg();
389406
if (isSCC(CCReg, MRI)) {
390-
unsigned Opcode = getS_CMPOpcode((CmpInst::Predicate)I.getOperand(1).getPredicate(), Size);
407+
int Opcode = getS_CMPOpcode(Pred, Size);
408+
if (Opcode == -1)
409+
return false;
391410
MachineInstr *ICmp = BuildMI(*BB, &I, DL, TII.get(Opcode))
392411
.add(I.getOperand(2))
393412
.add(I.getOperand(3));
@@ -400,8 +419,10 @@ bool AMDGPUInstructionSelector::selectG_ICMP(MachineInstr &I) const {
400419
return Ret;
401420
}
402421

403-
assert(Size == 32 || Size == 64);
404-
unsigned Opcode = getV_CMPOpcode((CmpInst::Predicate)I.getOperand(1).getPredicate(), Size);
422+
int Opcode = getV_CMPOpcode(Pred, Size);
423+
if (Opcode == -1)
424+
return false;
425+
405426
MachineInstr *ICmp = BuildMI(*BB, &I, DL, TII.get(Opcode),
406427
I.getOperand(0).getReg())
407428
.add(I.getOperand(2))
@@ -984,7 +1005,9 @@ bool AMDGPUInstructionSelector::select(MachineInstr &I,
9841005
case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
9851006
return selectG_INTRINSIC_W_SIDE_EFFECTS(I, CoverageInfo);
9861007
case TargetOpcode::G_ICMP:
987-
return selectG_ICMP(I);
1008+
if (selectG_ICMP(I))
1009+
return true;
1010+
return selectImpl(I, CoverageInfo);
9881011
case TargetOpcode::G_LOAD:
9891012
if (selectImpl(I, CoverageInfo))
9901013
return true;

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/ArrayRef.h"
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
21+
#include "llvm/IR/InstrTypes.h"
2122

2223
namespace {
2324
#define GET_GLOBALISEL_PREDICATE_BITSET
@@ -74,6 +75,7 @@ class AMDGPUInstructionSelector : public InstructionSelector {
7475
bool selectG_INTRINSIC(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
7576
bool selectG_INTRINSIC_W_SIDE_EFFECTS(MachineInstr &I,
7677
CodeGenCoverage &CoverageInfo) const;
78+
int getS_CMPOpcode(CmpInst::Predicate P, unsigned Size) const;
7779
bool selectG_ICMP(MachineInstr &I) const;
7880
bool hasVgprParts(ArrayRef<GEPInfo> AddrInfo) const;
7981
void getAddrModeInfo(const MachineInstr &Load, const MachineRegisterInfo &MRI,

0 commit comments

Comments
 (0)