summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-08-04 18:35:11 +0000
committerTim Northover <tnorthover@apple.com>2016-08-04 18:35:11 +0000
commit323358184e73d726357ad6e3272ca9f7931d174c (patch)
tree76e9d22b3999893043b4c05a1bb27918838cc1bc /llvm/lib
parentd2b37ada4dd402dcf643648127c4bddcd6a1691d (diff)
downloadbcm5719-llvm-323358184e73d726357ad6e3272ca9f7931d174c.tar.gz
bcm5719-llvm-323358184e73d726357ad6e3272ca9f7931d174c.zip
GlobalISel: add code to widen scalar G_ADD
llvm-svn: 277747
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp10
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp25
-rw-r--r--llvm/lib/CodeGen/GlobalISel/MachineLegalizer.cpp5
3 files changed, 39 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
index 5e737d5e2bb..09a8fa6001b 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -119,6 +119,11 @@ MachineInstrBuilder MachineIRBuilder::buildStore(LLT VTy, LLT PTy,
.addMemOperand(&MMO);
}
+MachineInstrBuilder MachineIRBuilder::buildAnyExtend(LLT Ty, unsigned Res,
+ unsigned Op) {
+ return buildInstr(TargetOpcode::G_ANYEXTEND, Ty).addDef(Res).addUse(Op);
+}
+
MachineInstrBuilder
MachineIRBuilder::buildExtract(LLT Ty, ArrayRef<unsigned> Results, unsigned Src,
ArrayRef<unsigned> Indexes) {
@@ -157,3 +162,8 @@ MachineInstrBuilder MachineIRBuilder::buildIntrinsic(ArrayRef<LLT> Tys,
MIB.addIntrinsicID(ID);
return MIB;
}
+
+MachineInstrBuilder MachineIRBuilder::buildTrunc(LLT Ty, unsigned Res,
+ unsigned Op) {
+ return buildInstr(TargetOpcode::G_TRUNC, Ty).addDef(Res).addUse(Op);
+}
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp b/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
index 55adbbd20ce..71d3206dc55 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
@@ -66,7 +66,30 @@ MachineLegalizeHelper::narrowScalar(MachineInstr &MI, LLT NarrowTy) {
MachineLegalizeHelper::LegalizeResult
MachineLegalizeHelper::widenScalar(MachineInstr &MI, LLT WideTy) {
- return UnableToLegalize;
+ switch (MI.getOpcode()) {
+ default:
+ return UnableToLegalize;
+ case TargetOpcode::G_ADD: {
+ // Perform operation at larger width (any extension is fine here, high bits
+ // don't affect the result) and then truncate the result back to the
+ // original type.
+ unsigned WideSize = WideTy.getSizeInBits();
+
+ MIRBuilder.setInstr(MI);
+
+ unsigned Src1Ext = MRI.createGenericVirtualRegister(WideSize);
+ unsigned Src2Ext = MRI.createGenericVirtualRegister(WideSize);
+ MIRBuilder.buildAnyExtend(WideTy, Src1Ext, MI.getOperand(1).getReg());
+ MIRBuilder.buildAnyExtend(WideTy, Src2Ext, MI.getOperand(2).getReg());
+
+ unsigned DstExt = MRI.createGenericVirtualRegister(WideSize);
+ MIRBuilder.buildAdd(WideTy, DstExt, Src1Ext, Src2Ext);
+
+ MIRBuilder.buildTrunc(MI.getType(), MI.getOperand(0).getReg(), DstExt);
+ MI.eraseFromParent();
+ return Legalized;
+ }
+ }
}
MachineLegalizeHelper::LegalizeResult
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineLegalizer.cpp b/llvm/lib/CodeGen/GlobalISel/MachineLegalizer.cpp
index 6856ed57a0b..881b5026fa6 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineLegalizer.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineLegalizer.cpp
@@ -25,6 +25,11 @@
using namespace llvm;
MachineLegalizer::MachineLegalizer() : TablesInitialized(false) {
+ // FIXME: these two can be legalized to the fundamental load/store Jakob
+ // proposed. Once loads & stores are supported.
+ DefaultActions[TargetOpcode::G_ANYEXTEND] = Legal;
+ DefaultActions[TargetOpcode::G_TRUNC] = Legal;
+
DefaultActions[TargetOpcode::G_ADD] = NarrowScalar;
}
OpenPOWER on IntegriCloud