aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorChen Zheng <czhengsz@cn.ibm.com>2023-01-03 09:44:03 +0000
committerChen Zheng <czhengsz@cn.ibm.com>2023-01-05 07:45:29 +0000
commitac93a4e77d1e60958b775ce5c68dd4b81d0e2050 (patch)
tree7c656bb11c70af0101fc5ec7ed71edff7e8b0ccb /llvm/lib
parent5006d82329c2d78b245127024a9f613236b459bc (diff)
downloadllvm-ac93a4e77d1e60958b775ce5c68dd4b81d0e2050.zip
llvm-ac93a4e77d1e60958b775ce5c68dd4b81d0e2050.tar.gz
llvm-ac93a4e77d1e60958b775ce5c68dd4b81d0e2050.tar.bz2
[PowerPC][GISel]fcmp support
This patch also includes: 1: CRRegBank support 2: Some workarounds in PPC table gen for anyext/setcc patterns selection. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D140878
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/PowerPC/GISel/PPCInstructionSelector.cpp8
-rw-r--r--llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp8
-rw-r--r--llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.cpp13
-rw-r--r--llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.h1
-rw-r--r--llvm/lib/Target/PowerPC/GISel/PPCRegisterBanks.td2
-rw-r--r--llvm/lib/Target/PowerPC/PPCGenRegisterBankInfo.def4
-rw-r--r--llvm/lib/Target/PowerPC/PPCInstrInfo.td32
7 files changed, 49 insertions, 19 deletions
diff --git a/llvm/lib/Target/PowerPC/GISel/PPCInstructionSelector.cpp b/llvm/lib/Target/PowerPC/GISel/PPCInstructionSelector.cpp
index a23fe7a..d737eec 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCInstructionSelector.cpp
+++ b/llvm/lib/Target/PowerPC/GISel/PPCInstructionSelector.cpp
@@ -99,7 +99,7 @@ static const TargetRegisterClass *getRegClass(LLT Ty, const RegisterBank *RB) {
if (RB->getID() == PPC::GPRRegBankID) {
if (Ty.getSizeInBits() == 64)
return &PPC::G8RCRegClass;
- if (Ty.getSizeInBits() == 32)
+ if (Ty.getSizeInBits() <= 32)
return &PPC::GPRCRegClass;
}
if (RB->getID() == PPC::FPRRegBankID) {
@@ -108,6 +108,12 @@ static const TargetRegisterClass *getRegClass(LLT Ty, const RegisterBank *RB) {
if (Ty.getSizeInBits() == 64)
return &PPC::F8RCRegClass;
}
+ if (RB->getID() == PPC::CRRegBankID) {
+ if (Ty.getSizeInBits() == 1)
+ return &PPC::CRBITRCRegClass;
+ if (Ty.getSizeInBits() == 4)
+ return &PPC::CRRCRegClass;
+ }
llvm_unreachable("Unknown RegBank!");
}
diff --git a/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp b/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
index 0fb12ab..1a25fcd 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
+++ b/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
@@ -20,6 +20,7 @@ using namespace LegalizeActions;
PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) {
using namespace TargetOpcode;
const LLT P0 = LLT::pointer(0, 64);
+ const LLT S1 = LLT::scalar(1);
const LLT S8 = LLT::scalar(8);
const LLT S16 = LLT::scalar(16);
const LLT S32 = LLT::scalar(32);
@@ -28,8 +29,8 @@ PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) {
getActionDefinitionsBuilder(G_CONSTANT)
.legalFor({S32, S64})
.clampScalar(0, S64, S64);
- getActionDefinitionsBuilder({G_ZEXT, G_SEXT})
- .legalForCartesianProduct({S64}, {S8, S16, S32})
+ getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})
+ .legalForCartesianProduct({S64}, {S1, S8, S16, S32})
.clampScalar(0, S64, S64);
getActionDefinitionsBuilder({G_AND, G_OR, G_XOR})
.legalFor({S64})
@@ -41,6 +42,9 @@ PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) {
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})
.legalFor({S32, S64});
+ getActionDefinitionsBuilder(G_FCMP).legalForCartesianProduct({S1},
+ {S32, S64});
+
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
.legalForCartesianProduct({S64}, {S32, S64});
diff --git a/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.cpp b/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.cpp
index af74ec9..69d9a04 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.cpp
+++ b/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.cpp
@@ -48,6 +48,9 @@ PPCRegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass &RC,
case PPC::VSSRCRegClassID:
case PPC::F4RCRegClassID:
return getRegBank(PPC::FPRRegBankID);
+ case PPC::CRRCRegClassID:
+ case PPC::CRBITRCRegClassID:
+ return getRegBank(PPC::CRRegBankID);
default:
llvm_unreachable("Unexpected register class");
}
@@ -87,6 +90,7 @@ PPCRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
// Extension ops.
case TargetOpcode::G_SEXT:
case TargetOpcode::G_ZEXT:
+ case TargetOpcode::G_ANYEXT:
assert(NumOperands <= 3 &&
"This code is for instructions with 3 or less operands");
OperandsMapping = getValueMapping(PMI_GPR64);
@@ -102,6 +106,15 @@ PPCRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
OperandsMapping = getValueMapping(Size == 32 ? PMI_FPR32 : PMI_FPR64);
break;
}
+ case TargetOpcode::G_FCMP: {
+ unsigned CmpSize = MRI.getType(MI.getOperand(2).getReg()).getSizeInBits();
+
+ OperandsMapping = getOperandsMapping(
+ {getValueMapping(PMI_CR), nullptr,
+ getValueMapping(CmpSize == 32 ? PMI_FPR32 : PMI_FPR64),
+ getValueMapping(CmpSize == 32 ? PMI_FPR32 : PMI_FPR64)});
+ break;
+ }
case TargetOpcode::G_CONSTANT:
OperandsMapping = getOperandsMapping({getValueMapping(PMI_GPR64), nullptr});
break;
diff --git a/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.h b/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.h
index f06a15a..885bdcb 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.h
+++ b/llvm/lib/Target/PowerPC/GISel/PPCRegisterBankInfo.h
@@ -32,6 +32,7 @@ protected:
PMI_GPR64 = 2,
PMI_FPR32 = 3,
PMI_FPR64 = 4,
+ PMI_CR = 5,
PMI_Min = PMI_GPR32,
};
diff --git a/llvm/lib/Target/PowerPC/GISel/PPCRegisterBanks.td b/llvm/lib/Target/PowerPC/GISel/PPCRegisterBanks.td
index b5f39e4..16f3bd8 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCRegisterBanks.td
+++ b/llvm/lib/Target/PowerPC/GISel/PPCRegisterBanks.td
@@ -15,3 +15,5 @@
def GPRRegBank : RegisterBank<"GPR", [G8RC, G8RC_NOX0]>;
/// Floating point Registers
def FPRRegBank : RegisterBank<"FPR", [VSSRC]>;
+/// Condition Registers
+def CRRegBank : RegisterBank<"CR", [CRRC]>;
diff --git a/llvm/lib/Target/PowerPC/PPCGenRegisterBankInfo.def b/llvm/lib/Target/PowerPC/PPCGenRegisterBankInfo.def
index 897fe25..f7e79ae 100644
--- a/llvm/lib/Target/PowerPC/PPCGenRegisterBankInfo.def
+++ b/llvm/lib/Target/PowerPC/PPCGenRegisterBankInfo.def
@@ -22,6 +22,8 @@ RegisterBankInfo::PartialMapping PPCGenRegisterBankInfo::PartMappings[]{
{0, 32, PPC::FPRRegBank},
// 3: FPR 64-bit value
{0, 64, PPC::FPRRegBank},
+ // 4: CR 4-bit value
+ {0, 4, PPC::CRRegBank},
};
// ValueMappings.
@@ -55,6 +57,8 @@ RegisterBankInfo::ValueMapping PPCGenRegisterBankInfo::ValMappings[]{
{&PPCGenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
{&PPCGenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
{&PPCGenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
+ // 13: CR 4-bit value.
+ {&PPCGenRegisterBankInfo::PartMappings[PMI_CR - PMI_Min], 1},
};
// TODO Too simple!
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.td b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
index 0b39a2b..ff21294 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -3327,9 +3327,9 @@ def : Pat<(i64 (sext i1:$in)),
// FIXME: We should choose either a zext or a sext based on other constants
// already around.
def : Pat<(i32 (anyext i1:$in)),
- (SELECT_I4 $in, (LI 1), (LI 0))>;
+ (SELECT_I4 i1:$in, (LI 1), (LI 0))>;
def : Pat<(i64 (anyext i1:$in)),
- (SELECT_I8 $in, (LI8 1), (LI8 0))>;
+ (SELECT_I8 i1:$in, (LI8 1), (LI8 0))>;
// match setcc on i1 variables.
// CRANDC is:
@@ -3735,34 +3735,34 @@ defm : CRNotPat<(i1 (setcc i64:$s1, i64:$s2, SETNE)),
multiclass FSetCCPat<SDPatternOperator SetCC, ValueType Ty, I FCmp> {
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETUGE)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_lt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_lt)>;
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETGE)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_lt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_lt)>;
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETULE)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_gt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_gt)>;
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETLE)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_gt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_gt)>;
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETUNE)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_eq)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_eq)>;
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETNE)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_eq)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_eq)>;
defm : CRNotPat<(i1 (SetCC Ty:$s1, Ty:$s2, SETO)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_un)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_un)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETOLT)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_lt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_lt)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETLT)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_lt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_lt)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETOGT)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_gt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_gt)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETGT)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_gt)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_gt)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETOEQ)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_eq)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_eq)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETEQ)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_eq)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_eq)>;
def : Pat<(i1 (SetCC Ty:$s1, Ty:$s2, SETUO)),
- (EXTRACT_SUBREG (FCmp $s1, $s2), sub_un)>;
+ (EXTRACT_SUBREG (FCmp Ty:$s1, Ty:$s2), sub_un)>;
}
let Predicates = [HasFPU] in {