diff options
author | Thomas Lively <tlively@google.com> | 2018-12-20 04:20:32 +0000 |
---|---|---|
committer | Thomas Lively <tlively@google.com> | 2018-12-20 04:20:32 +0000 |
commit | feb18fe927d33e1d5a7bd873451ac9a1a76c7141 (patch) | |
tree | 2420931912049190a3600369e0fa8b044b0e45e4 /llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | |
parent | 321bfb210a2d5a6da659e74715d83c7b2dc752eb (diff) | |
download | llvm-feb18fe927d33e1d5a7bd873451ac9a1a76c7141.zip llvm-feb18fe927d33e1d5a7bd873451ac9a1a76c7141.tar.gz llvm-feb18fe927d33e1d5a7bd873451ac9a1a76c7141.tar.bz2 |
[WebAssembly] Emit a splat for v128 IMPLICIT_DEF
Summary:
This is a code size savings and is also important to get runnable code
while engines do not support v128.const.
Reviewers: aheejin, dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D55910
llvm-svn: 349724
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp index dc2aab8..efd8dbe 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -98,7 +98,8 @@ static void ImposeStackOrdering(MachineInstr *MI) { static void ConvertImplicitDefToConstZero(MachineInstr *MI, MachineRegisterInfo &MRI, const TargetInstrInfo *TII, - MachineFunction &MF) { + MachineFunction &MF, + LiveIntervals &LIS) { assert(MI->getOpcode() == TargetOpcode::IMPLICIT_DEF); const auto *RegClass = MRI.getRegClass(MI->getOperand(0).getReg()); @@ -119,10 +120,13 @@ static void ConvertImplicitDefToConstZero(MachineInstr *MI, Type::getDoubleTy(MF.getFunction().getContext()))); MI->addOperand(MachineOperand::CreateFPImm(Val)); } else if (RegClass == &WebAssembly::V128RegClass) { - // TODO: make splat instead of constant - MI->setDesc(TII->get(WebAssembly::CONST_V128_v16i8)); - for (int I = 0; I < 16; ++I) - MI->addOperand(MachineOperand::CreateImm(0)); + unsigned TempReg = MRI.createVirtualRegister(&WebAssembly::I32RegClass); + MI->setDesc(TII->get(WebAssembly::SPLAT_v4i32)); + MI->addOperand(MachineOperand::CreateReg(TempReg, false)); + MachineInstr *Const = BuildMI(*MI->getParent(), MI, MI->getDebugLoc(), + TII->get(WebAssembly::CONST_I32), TempReg) + .addImm(0); + LIS.InsertMachineInstrInMaps(*Const); } else { llvm_unreachable("Unexpected reg class"); } @@ -895,7 +899,7 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) { // to a constant 0 so that the def is explicit, and the push/pop // correspondence is maintained. if (Insert->getOpcode() == TargetOpcode::IMPLICIT_DEF) - ConvertImplicitDefToConstZero(Insert, MRI, TII, MF); + ConvertImplicitDefToConstZero(Insert, MRI, TII, MF, LIS); // We stackified an operand. Add the defining instruction's operands to // the worklist stack now to continue to build an ever deeper tree. |