<div dir="ltr">There's not a good way to enforce the number of bits in the immediate in IR. The best you can do is use an oversized type and have isel reject selecting an instruction if the immediate doesn't fit. If you're creating the intrinsic in clang from a builtin you can also range check the immediate in lib/Sema/SemaChecking.cpp to give a nice diagnostic to the user.<div><br></div><div>You might want to use llvm_i32_ty so that's at least a legal type on RV32. Or llvm_anyint_ty and pick the correct type for RV32 or RV64 when you create the intrinsic.<br><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 5, 2021 at 2:43 AM Sai Venkata Krishnan V via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello Everyone<br><div>   I am trying to add an custom Intrinsic to the RISCV backend, which operates on a <i>simm12 </i>operand. I figured the steps to add it to <i>lib/llvm/Target/RISCV/RISCVInstrInfo.td </i>& <i>lib/llvm/Target/RISCV/RISCVInstrFormats.td. </i>But I am not sure how to declare the intrinsic in <i>llvm/include/IR/IntrinsicsRISCV.td </i>. Specifically, since I require a <i>imm12 </i>operand, how should I specify that in intrinsic declaration? Is there a corresponding <i>llvm_i12_ty </i>which I can specify and make use of <i>ImmArg<> </i>to specify that the operand is an immediate, or should I just use the nearest size type, i.e. <i>llvm_i16_ty </i>and make use of the <i>ImmArg<></i> ?</div><div><br></div><div>Please guide me on this</div><div><br></div><div>Thanking you </div><div>Sai</div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>