I'm trying to add intrinsics for the Signal Processing Engine (FPU/vector unit) on some PowerPC cores, but running into a problem. Some of the instructions take an immediate operand, but I can't figure out how to make the intrinsic use an immediate, it just wants to load a register as an argument to the function. Is there any way in the .td file to describe the intrinsic as taking an immediate, or do I need to generate an intermediate instruction identifier? Thanks, Justin
The fact that the intrinsic takes an immediate is usually encoded as part of the isel pattern selection For example from an x86 intrinsic/instruction: def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap", [(int_x86_int imm:$trap)], IIC_INT>; I'm slightly confused by your question though as you mention register which sort of implies you're looking at PowerPC assembly. But you also mention a function, but the intrinsic should have been turned into instructions before assembly and there should be no function call. ~Craig On Sun, Dec 17, 2017 at 8:26 PM, Justin Hibbits via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I'm trying to add intrinsics for the Signal Processing Engine > (FPU/vector unit) on some PowerPC cores, but running into a problem. > Some of the instructions take an immediate operand, but I can't figure > out how to make the intrinsic use an immediate, it just wants to load > a register as an argument to the function. Is there any way in the > .td file to describe the intrinsic as taking an immediate, or do I > need to generate an intermediate instruction identifier? > > Thanks, > Justin > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171217/664dc5b7/attachment.html>
Krzysztof Parzyszek via llvm-dev
2017-Dec-18 13:47 UTC
[llvm-dev] Immediates in intrinsics
To add to this: it is the "imm:$trap" in the selection pattern that does it (the "imm:" part of it, to be even more specific). -Krzysztof On 12/17/2017 11:01 PM, Craig Topper via llvm-dev wrote:> The fact that the intrinsic takes an immediate is usually encoded as > part of the isel pattern selection > > For example from an x86 intrinsic/instruction: > > def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap", > [(int_x86_int imm:$trap)], IIC_INT>; > > I'm slightly confused by your question though as you mention register > which sort of implies you're looking at PowerPC assembly. But you also > mention a function, but the intrinsic should have been turned into > instructions before assembly and there should be no function call. > > ~Craig > > On Sun, Dec 17, 2017 at 8:26 PM, Justin Hibbits via llvm-dev > <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: > > I'm trying to add intrinsics for the Signal Processing Engine > (FPU/vector unit) on some PowerPC cores, but running into a problem. > Some of the instructions take an immediate operand, but I can't figure > out how to make the intrinsic use an immediate, it just wants to load > a register as an argument to the function. Is there any way in the > .td file to describe the intrinsic as taking an immediate, or do I > need to generate an intermediate instruction identifier? > > Thanks, > Justin > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> > > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Hi Craig, Thanks for your reply. The instructions in question don't have an associated pattern currently, I've been trying to do the pattern matching in the intrinsic Pat<>, which may be the wrong way to go. The output of the following test case: declare <2 x i32> @llvm.ppc.spe.evaddiw ( <2 x i32>, i32 ) define <2 x i32> @test_int_ppc_spe_evaddiw ( <2 x i32> %A ) { entry: %0 = tail call <2 x i32> @llvm.ppc.spe.evaddiw ( <2 x i32> %A, i32 1 ) ret <2 x i32> %0 } looks like: test_int_ppc_spe_evaddiw: # @test_int_ppc_spe_evaddiw .Lfunc_begin2: .cfi_startproc # %bb.0: # %entry li 4, 1 evaddiw 3, Assertion failed: (isImm() && "This is not an immediate"), function getImm, file /home/chmeee/llvm_git/llvm/include/llvm/MC/MCInst.h, line 77. So the instruction is expecting an immediate, but r4 is getting loaded with the constant I expected to be the immediate, so it's rejecting it. After reading Nemanja's reply, I checked the int_ppc_vsx_xxinsertw and discovered I was simply missing a 'imm:' conversion in the intrinsic pattern. So my pattern was: def : Pat<(int_ppc_spe_evaddiw v2i32:$A, i32:$B), (EVADDIW $A, $B)>; and I changed it to: def : Pat<(int_ppc_spe_evaddiw v2i32:$A, i32:$B), (EVADDIW $A, imm:$B)>; Now this intrinsic works correctly. - Justin On Sun, Dec 17, 2017 at 11:01 PM, Craig Topper <craig.topper at gmail.com> wrote:> The fact that the intrinsic takes an immediate is usually encoded as part of > the isel pattern selection > > For example from an x86 intrinsic/instruction: > > def INT : Ii8<0xcd, RawFrm, (outs), (ins u8imm:$trap), "int\t$trap", > [(int_x86_int imm:$trap)], IIC_INT>; > > I'm slightly confused by your question though as you mention register which > sort of implies you're looking at PowerPC assembly. But you also mention a > function, but the intrinsic should have been turned into instructions before > assembly and there should be no function call. > > ~Craig > > On Sun, Dec 17, 2017 at 8:26 PM, Justin Hibbits via llvm-dev > <llvm-dev at lists.llvm.org> wrote: >> >> I'm trying to add intrinsics for the Signal Processing Engine >> (FPU/vector unit) on some PowerPC cores, but running into a problem. >> Some of the instructions take an immediate operand, but I can't figure >> out how to make the intrinsic use an immediate, it just wants to load >> a register as an argument to the function. Is there any way in the >> .td file to describe the intrinsic as taking an immediate, or do I >> need to generate an intermediate instruction identifier? >> >> Thanks, >> Justin >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >
Reasonably Related Threads
- x86 instruction format which takes a single 64-bit immediate
- x86 instruction format which takes a single 64-bit immediate
- [LLVMdev] MC X86 lacking support for hyphenated VIA Padlock instructions
- [LLVMdev] MC X86 lacking support for hyphenated VIA Padlock instructions
- [LLVMdev] MC X86 lacking support for hyphenated VIA Padlock instructions