aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-08-19 20:48:16 +0000
committerTim Northover <tnorthover@apple.com>2016-08-19 20:48:16 +0000
commitd5c23bcfc9287a21280116ec1a5364f54c2df10c (patch)
tree82ba06131c63b20db973d6749e01faaacce7c57a /llvm/lib/CodeGen
parent8075b823223ea465d8fc7d7720a8abbee5798b77 (diff)
downloadllvm-d5c23bcfc9287a21280116ec1a5364f54c2df10c.zip
llvm-d5c23bcfc9287a21280116ec1a5364f54c2df10c.tar.gz
llvm-d5c23bcfc9287a21280116ec1a5364f54c2df10c.tar.bz2
GlobalISel: translate floating-point comparisons
llvm-svn: 279319
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp29
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp11
2 files changed, 29 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 1a243c5..36150c6 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -100,17 +100,24 @@ bool IRTranslator::translateBinaryOp(unsigned Opcode, const User &U) {
return true;
}
-bool IRTranslator::translateICmp(const User &U) {
- const CmpInst &CI = cast<CmpInst>(U);
- unsigned Op0 = getOrCreateVReg(*CI.getOperand(0));
- unsigned Op1 = getOrCreateVReg(*CI.getOperand(1));
- unsigned Res = getOrCreateVReg(CI);
- CmpInst::Predicate Pred = CI.getPredicate();
-
- assert(isa<ICmpInst>(CI) && "only integer comparisons supported now");
- assert(CmpInst::isIntPredicate(Pred) && "only int comparisons supported now");
- MIRBuilder.buildICmp({LLT{*CI.getType()}, LLT{*CI.getOperand(0)->getType()}},
- Pred, Res, Op0, Op1);
+bool IRTranslator::translateCompare(const User &U) {
+ const CmpInst *CI = dyn_cast<CmpInst>(&U);
+ unsigned Op0 = getOrCreateVReg(*U.getOperand(0));
+ unsigned Op1 = getOrCreateVReg(*U.getOperand(1));
+ unsigned Res = getOrCreateVReg(U);
+ CmpInst::Predicate Pred =
+ CI ? CI->getPredicate() : static_cast<CmpInst::Predicate>(
+ cast<ConstantExpr>(U).getPredicate());
+
+ if (CmpInst::isIntPredicate(Pred))
+ MIRBuilder.buildICmp(
+ {LLT{*U.getType()}, LLT{*U.getOperand(0)->getType()}}, Pred, Res, Op0,
+ Op1);
+ else
+ MIRBuilder.buildFCmp(
+ {LLT{*U.getType()}, LLT{*U.getOperand(0)->getType()}}, Pred, Res, Op0,
+ Op1);
+
return true;
}
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
index 2fe6eab..aa64be5 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -222,6 +222,17 @@ MachineInstrBuilder MachineIRBuilder::buildICmp(ArrayRef<LLT> Tys,
.addUse(Op1);
}
+MachineInstrBuilder MachineIRBuilder::buildFCmp(ArrayRef<LLT> Tys,
+ CmpInst::Predicate Pred,
+ unsigned Res, unsigned Op0,
+ unsigned Op1) {
+ return buildInstr(TargetOpcode::G_FCMP, Tys)
+ .addDef(Res)
+ .addPredicate(Pred)
+ .addUse(Op0)
+ .addUse(Op1);
+}
+
MachineInstrBuilder MachineIRBuilder::buildSelect(LLT Ty, unsigned Res,
unsigned Tst,
unsigned Op0, unsigned Op1) {