[llvm] r261465 - [WebAssembly] Support physical registers in the rewrite-to-discard optimization.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 20 19:27:23 PST 2016
Author: djg
Date: Sat Feb 20 21:27:22 2016
New Revision: 261465
URL: http://llvm.org/viewvc/llvm-project?rev=261465&view=rev
Log:
[WebAssembly] Support physical registers in the rewrite-to-discard optimization.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
llvm/trunk/test/CodeGen/WebAssembly/userstack.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp?rev=261465&r1=261464&r2=261465&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp Sat Feb 20 21:27:22 2016
@@ -48,16 +48,22 @@ FunctionPass *llvm::createWebAssemblyPee
return new WebAssemblyPeephole();
}
+static const TargetRegisterClass *GetRegClass(const MachineRegisterInfo &MRI,
+ unsigned RegNo) {
+ return TargetRegisterInfo::isVirtualRegister(RegNo)
+ ? MRI.getRegClass(RegNo)
+ : MRI.getTargetRegisterInfo()->getMinimalPhysRegClass(RegNo);
+}
+
/// If desirable, rewrite NewReg to a discard register.
static bool MaybeRewriteToDiscard(unsigned OldReg, unsigned NewReg,
MachineOperand &MO,
WebAssemblyFunctionInfo &MFI,
MachineRegisterInfo &MRI) {
bool Changed = false;
- // TODO: Handle SP/physregs
- if (OldReg == NewReg && TargetRegisterInfo::isVirtualRegister(NewReg)) {
+ if (OldReg == NewReg) {
Changed = true;
- unsigned NewReg = MRI.createVirtualRegister(MRI.getRegClass(OldReg));
+ unsigned NewReg = MRI.createVirtualRegister(GetRegClass(MRI, OldReg));
MO.setReg(NewReg);
MO.setIsDead();
MFI.stackifyVReg(NewReg);
@@ -121,9 +127,7 @@ bool WebAssemblyPeephole::runOnMachineFu
unsigned OldReg = MO.getReg();
unsigned NewReg = Op2.getReg();
- // TODO: Handle SP/physregs in MaybeRewriteToDiscard
- if (TargetRegisterInfo::isVirtualRegister(NewReg) &&
- (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg)))
+ if (GetRegClass(MRI, NewReg) != GetRegClass(MRI, OldReg))
report_fatal_error("Peephole: call to builtin function with "
"wrong signature, from/to mismatch");
Changed |= MaybeRewriteToDiscard(OldReg, NewReg, MO, MFI, MRI);
Modified: llvm/trunk/test/CodeGen/WebAssembly/userstack.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/userstack.ll?rev=261465&r1=261464&r2=261465&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/userstack.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/userstack.ll Sat Feb 20 21:27:22 2016
@@ -14,7 +14,7 @@ define void @alloca32() {
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L4]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
%retval = alloca i32
; CHECK: i32.const $push[[L0:.+]]=, 0
; CHECK: i32.store {{.*}}=, 12([[SP]]), $pop[[L0]]
@@ -22,7 +22,7 @@ define void @alloca32() {
; CHECK: i32.const $push[[L5:.+]]=, 16
; CHECK-NEXT: i32.add [[SP]]=, [[SP]], $pop[[L5]]
; CHECK-NEXT: i32.const $push[[L6:.+]]=, __stack_pointer
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L6]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), [[SP]]
ret void
}
@@ -34,7 +34,7 @@ define void @alloca3264() {
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L4]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
%r1 = alloca i32
%r2 = alloca double
; CHECK: i32.const $push[[L3:.+]]=, 0
@@ -46,7 +46,7 @@ define void @alloca3264() {
; CHECK: i32.const $push[[L5:.+]]=, 16
; CHECK-NEXT: i32.add [[SP]]=, [[SP]], $pop[[L5]]
; CHECK-NEXT: i32.const $push[[L6:.+]]=, __stack_pointer
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L6]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), [[SP]]
ret void
}
@@ -58,7 +58,7 @@ define void @allocarray() {
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 32{{$}}
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L4]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
%r = alloca [5 x i32]
; CHECK-NEXT: i32.const $push[[L4:.+]]=, 12
@@ -76,7 +76,7 @@ define void @allocarray() {
; CHECK: i32.const $push[[L11:.+]]=, 32
; CHECK-NEXT: i32.add [[SP]]=, [[SP]], $pop[[L11]]
; CHECK-NEXT: i32.const $push[[L12:.+]]=, __stack_pointer
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L12]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L12]]), [[SP]]
ret void
}
@@ -125,7 +125,7 @@ define void @allocarray_inbounds() {
; CHECK: i32.const $push[[L5:.+]]=, 32
; CHECK-NEXT: i32.add [[SP]]=, [[SP]], $pop[[L5]]
; CHECK-NEXT: i32.const $push[[L6:.+]]=, __stack_pointer
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L6]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), [[SP]]
ret void
}
@@ -136,7 +136,7 @@ define void @dynamic_alloca(i32 %alloc)
; CHECK-NEXT: copy_local [[FP:.+]]=, [[SP]]
; Target independent codegen bumps the stack pointer
; CHECK: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L4]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
%r = alloca i32, i32 %alloc
; Target-independent codegen also calculates the store addr
store i32 0, i32* %r
@@ -161,7 +161,7 @@ define void @dynamic_static_alloca(i32 %
; CHECK: i32.const $push[[L5:.+]]=, 16
; CHECK-NEXT: i32.add [[SP]]=, [[FP]], $pop[[L5]]
; CHECK-NEXT: i32.const $push[[L6:.+]]=, __stack_pointer
- ; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L6]]), [[SP]]
+ ; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), [[SP]]
ret void
}
@@ -195,7 +195,7 @@ declare i8* @llvm.frameaddress(i32)
; CHECK-NEXT: i32.load [[SP:.+]]=, 0($pop[[L1]])
; CHECK-NEXT: copy_local [[FP:.+]]=, [[SP]]
; CHECK-NEXT: i32.const $push[[L2:.+]]=, __stack_pointer{{$}}
-; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L2]]), [[SP]]
+; CHECK-NEXT: i32.store $discard=, 0($pop[[L2]]), [[SP]]
; CHECK-NEXT: call use_i8_star at FUNCTION, [[FP]]
; CHECK-NEXT: i32.const $push[[L6:.+]]=, __stack_pointer
; CHECK-NEXT: i32.store [[SP]]=, 0($pop[[L6]]), [[FP]]
More information about the llvm-commits
mailing list