[PATCH] D118312: [X86] TCRETURNmi fix for 32bit platform
Tong Zhang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 1 14:58:15 PST 2022
ztong0001 updated this revision to Diff 405109.
ztong0001 added a comment.
Add test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118312/new/
https://reviews.llvm.org/D118312
Files:
llvm/lib/Target/X86/X86InstrCompiler.td
llvm/test/CodeGen/X86/tailcall-3regparm.ll
Index: llvm/test/CodeGen/X86/tailcall-3regparm.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/tailcall-3regparm.ll
@@ -0,0 +1,30 @@
+; RUN: llc < %s -mtriple=i686-linux-gnu -mcpu=pentium | FileCheck %s
+
+; Tail call should not make register allocation fail (x86-32)
+
+%struct.anon = type { i32 (%struct.BIG_PARM*, i8*)*, i32 ()*, i32 ()*, i32 ()*, i32 ()*, i32 ()*, i32 ()* }
+%struct.BIG_PARM = type { i32 }
+
+ at vtable = internal unnamed_addr constant [1 x %struct.anon] [%struct.anon { i32 (%struct.BIG_PARM*, i8*)* inttoptr (i32 -559038737 to i32 (%struct.BIG_PARM*, i8*)*), i32 ()* null, i32 ()* null, i32 ()* null, i32 ()* null, i32 ()* null, i32 ()* null }], align 4
+
+; Function Attrs: nounwind uwtable
+define dso_local i32 @something(%struct.BIG_PARM* inreg noundef %a, i8* inreg noundef %b) local_unnamed_addr #0 {
+entry:
+ ; CHECK: movl (%eax), %ecx
+ ; CHECK-NEXT: leal (%ecx,%ecx,8), %esi
+ ; CHECK-NEXT: leal (%esi,%esi,2), %esi
+ ; CHECK-NEXT: movl vtable(%ecx,%esi), %ecx
+ ; CHECK-NEXT: popl %esi
+ ; CHECK: jmpl *%ecx
+ %ver = getelementptr inbounds %struct.BIG_PARM, %struct.BIG_PARM* %a, i32 0, i32 0
+ %0 = load i32, i32* %ver, align 4
+ %foo = getelementptr [1 x %struct.anon], [1 x %struct.anon]* @vtable, i32 0, i32 %0, i32 0
+ %1 = load i32 (%struct.BIG_PARM*, i8*)*, i32 (%struct.BIG_PARM*, i8*)** %foo, align 4
+ %call = tail call i32 %1(%struct.BIG_PARM* inreg noundef %a, i8* inreg noundef %b) #1
+ ret i32 %call
+}
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"NumRegisterParameters", i32 3}
+
Index: llvm/lib/Target/X86/X86InstrCompiler.td
===================================================================
--- llvm/lib/Target/X86/X86InstrCompiler.td
+++ llvm/lib/Target/X86/X86InstrCompiler.td
@@ -1235,6 +1235,22 @@
return true;
}]>;
+def X86tcret_1reg : PatFrag<(ops node:$ptr, node:$off),
+ (X86tcret node:$ptr, node:$off), [{
+ // X86tcret args: (*chain, ptr, imm, regs..., glue)
+ unsigned NumRegs = 1;
+ LoadSDNode* ld = dyn_cast<LoadSDNode>(N->getOperand(1));
+ const SDValue& BasePtr = ld->getBasePtr();
+ if (isa<FrameIndexSDNode>(BasePtr))
+ NumRegs = 3;
+ else if (N->getNumOperands() && isa<GlobalAddressSDNode>(BasePtr->getOperand(0)))
+ NumRegs = 3;
+ for (unsigned i = 3, e = N->getNumOperands(); i != e; ++i)
+ if (isa<RegisterSDNode>(N->getOperand(i)) && ( NumRegs-- == 0))
+ return false;
+ return true;
+}]>;
+
def : Pat<(X86tcret ptr_rc_tailcall:$dst, timm:$off),
(TCRETURNri ptr_rc_tailcall:$dst, timm:$off)>,
Requires<[Not64BitMode, NotUseIndirectThunkCalls]>;
@@ -1242,7 +1258,8 @@
// FIXME: This is disabled for 32-bit PIC mode because the global base
// register which is part of the address mode may be assigned a
// callee-saved register.
-def : Pat<(X86tcret (load addr:$dst), timm:$off),
+// Similar to X86tcret_6regs, here we only have 1 register left
+def : Pat<(X86tcret_1reg (load addr:$dst), timm:$off),
(TCRETURNmi addr:$dst, timm:$off)>,
Requires<[Not64BitMode, IsNotPIC, NotUseIndirectThunkCalls]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118312.405109.patch
Type: text/x-patch
Size: 3156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/d01845bc/attachment.bin>
More information about the llvm-commits
mailing list