summaryrefslogtreecommitdiff
path: root/lib/Target
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2011-10-26 22:47:55 +0000
committerChad Rosier <mcrosier@apple.com>2011-10-26 22:47:55 +0000
commit530f7cefd3082e8aaa74b7d65636f30d0312b6ec (patch)
tree049b849c9088097e51a5e248eced2b90133fb7c2 /lib/Target
parent684457d179fcfdf8c1f8ee9f66cc40665ecc648c (diff)
downloadllvm-530f7cefd3082e8aaa74b7d65636f30d0312b6ec.tar.gz
llvm-530f7cefd3082e8aaa74b7d65636f30d0312b6ec.tar.bz2
llvm-530f7cefd3082e8aaa74b7d65636f30d0312b6ec.tar.xz
Factor out an EmitCmp function that can be used by both SelectCmp and
SelectBranch. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/ARM/ARMFastISel.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/Target/ARM/ARMFastISel.cpp b/lib/Target/ARM/ARMFastISel.cpp
index 73fd2e2668..4e0ad366e0 100644
--- a/lib/Target/ARM/ARMFastISel.cpp
+++ b/lib/Target/ARM/ARMFastISel.cpp
@@ -173,6 +173,7 @@ class ARMFastISel : public FastISel {
private:
bool isTypeLegal(Type *Ty, MVT &VT);
bool isLoadTypeLegal(Type *Ty, MVT &VT);
+ bool ARMEmitCmp(Type *Ty, const Value *Src1Value, const Value *Src2Value);
bool ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr);
bool ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr);
bool ARMComputeAddress(const Value *Obj, Address &Addr);
@@ -1214,54 +1215,58 @@ bool ARMFastISel::SelectBranch(const Instruction *I) {
return true;
}
-bool ARMFastISel::SelectCmp(const Instruction *I) {
- const CmpInst *CI = cast<CmpInst>(I);
-
+bool ARMFastISel::ARMEmitCmp(Type *Ty, const Value *Src1Value,
+ const Value *Src2Value) {
MVT VT;
- Type *Ty = CI->getOperand(0)->getType();
if (!isTypeLegal(Ty, VT))
return false;
- bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
- if (isFloat && !Subtarget->hasVFP2())
+ if ((Ty->isFloatTy() || Ty->isDoubleTy()) && !Subtarget->hasVFP2())
return false;
unsigned CmpOpc;
- unsigned CondReg;
switch (VT.SimpleTy) {
default: return false;
// TODO: Verify compares.
case MVT::f32:
CmpOpc = ARM::VCMPES;
- CondReg = ARM::FPSCR;
break;
case MVT::f64:
CmpOpc = ARM::VCMPED;
- CondReg = ARM::FPSCR;
break;
case MVT::i32:
CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr;
- CondReg = ARM::CPSR;
break;
}
+ unsigned Src1 = getRegForValue(Src1Value);
+ if (Src1 == 0) return false;
+
+ unsigned Src2 = getRegForValue(Src2Value);
+ if (Src2 == 0) return false;
+
+ AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
+ .addReg(Src1).addReg(Src2));
+ return true;
+}
+
+bool ARMFastISel::SelectCmp(const Instruction *I) {
+ const CmpInst *CI = cast<CmpInst>(I);
+
// Get the compare predicate.
ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate());
// We may not handle every CC for now.
if (ARMPred == ARMCC::AL) return false;
- unsigned Arg1 = getRegForValue(CI->getOperand(0));
- if (Arg1 == 0) return false;
-
- unsigned Arg2 = getRegForValue(CI->getOperand(1));
- if (Arg2 == 0) return false;
-
- AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
- .addReg(Arg1).addReg(Arg2));
+ // Emit the compare.
+ Type *Ty = CI->getOperand(0)->getType();
+ if (!ARMEmitCmp(Ty, CI->getOperand(0), CI->getOperand(1)))
+ return false;
// For floating point we need to move the result to a comparison register
// that we can then use for branches.
+ bool isFloat = Ty->isFloatTy() || Ty->isDoubleTy();
if (isFloat)
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
TII.get(ARM::FMSTAT)));
@@ -1275,6 +1280,7 @@ bool ARMFastISel::SelectCmp(const Instruction *I) {
Constant *Zero
= ConstantInt::get(Type::getInt32Ty(*Context), 0);
unsigned ZeroReg = TargetMaterializeConstant(Zero);
+ unsigned CondReg = isFloat ? ARM::FPSCR : ARM::CPSR;
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg)
.addReg(ZeroReg).addImm(1)
.addImm(ARMPred).addReg(CondReg);