[PATCH] D149211: [GlobalISel][InlineAsm][X86]Fallback on DAG ISel when lowering inline assembly
Mingming Liu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 15:49:10 PDT 2023
mingmingl created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
mingmingl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently inline assembly lowering reports error as shown in https://gcc.godbolt.org/z/Kdx7e3n9M
- This doesn't fix https://github.com/llvm/llvm-project/issues/62343 but gives a workaround by tuning 'global-isel-abort'.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149211
Files:
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/test/CodeGen/X86/GlobalISel/x86_64-fallback.ll
Index: llvm/test/CodeGen/X86/GlobalISel/x86_64-fallback.ll
===================================================================
--- llvm/test/CodeGen/X86/GlobalISel/x86_64-fallback.ll
+++ llvm/test/CodeGen/X86/GlobalISel/x86_64-fallback.ll
@@ -27,3 +27,12 @@
call void @ScaleObjectOverwrite_3(ptr %index, ptr byval(%struct.PointListStruct) %index)
ret void
}
+
+; Check that inline assembly lowering falls back to instruction selection.
+; FALLBACK-WITH-REPORT-ERR: <unknown>:0:0: unable to translate instruction: call: ' %2 = tail call i32 asm "and $$3, ${0:k}", "=r,0,~{dirflag},~{fpsr},~{flags}"(i32 %0)' (in function: inline_asm_func)
+; FALLBACK-WITH-REPORT-ERR: warning: Instruction selection used fallback path for inline_asm_func
+; FALLBACK-WITH-REPORT-OUT-LABEL: inline_asm_func:
+define i32 @inline_asm_func(i32 %0) {
+ %2 = tail call i32 asm "and $$3, ${0:k}", "=r,0,~{dirflag},~{fpsr},~{flags}"(i32 %0)
+ ret i32 %2
+}
Index: llvm/lib/Target/X86/X86ISelLowering.h
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.h
+++ llvm/lib/Target/X86/X86ISelLowering.h
@@ -1455,6 +1455,8 @@
return nullptr; // nothing to do, move along.
}
+ bool fallBackToDAGISel(const Instruction& Inst) const override;
+
Register getRegisterByName(const char* RegName, LLT VT,
const MachineFunction &MF) const override;
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -29397,6 +29397,12 @@
return FrameAddr;
}
+bool X86TargetLowering::fallBackToDAGISel(const Instruction& Inst) const {
+ auto* CI = dyn_cast<CallInst>(&Inst);
+
+ return CI && CI->isInlineAsm();
+}
+
// FIXME? Maybe this could be a TableGen attribute on some registers and
// this table could be generated automatically from RegInfo.
Register X86TargetLowering::getRegisterByName(const char* RegName, LLT VT,
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2426,8 +2426,11 @@
if (isa<GCStatepointInst, GCRelocateInst, GCResultInst>(U))
return false;
- if (CI.isInlineAsm())
- return translateInlineAsm(CI, MIRBuilder);
+ if (CI.isInlineAsm()) {
+ const Instruction& Instr = cast<Instruction>(CI);
+ auto& TLI = *MF->getSubtarget().getTargetLowering();
+ return TLI.fallBackToDAGISel(Instr) ? false : translateInlineAsm(CI, MIRBuilder);
+ }
diagnoseDontCall(CI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149211.516961.patch
Type: text/x-patch
Size: 2715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230425/fe91a571/attachment.bin>
More information about the llvm-commits
mailing list