[llvm-dev] A Question about Using PatFrag

Ben Shi via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 13 07:23:14 PDT 2021


Hello,


I am using PatFrag with the following way but rejected.


+def AddShlShlShift1 : PatFrag<(ops node:$A, node:$B, node:$C, node:$D),
+                              (add (shl node:$A, node:$B), (shl node:$C, node:$D)), [{
+ // Some condition check code.
+}]>;
+
+def : Pat<(AddShlShlShift1 GPR:$rs1, uimmlog2xlen:$sh1,
+                           GPR:$rs2, uimmlog2xlen:$sh2),
+          (SLLI (SH1ADD GPR:$rs1, GPR:$rs2),
+                (TrailingZerosXForm uimmlog2xlen:$sh2))>;


The error message is "error: In anonymous_5561: Pattern has dead named input: $sh1"


Since the operand $Sh1 is absorbed in the the SH1ADD instruction, it is no long been used.


What is a proper way to do this? Only use DAG2DAG? Or I can define a pseudo SDNode which just to be its operand-0 ?
Such as
+def : Pat<(AddShlShlShift1 GPR:$rs1, uimmlog2xlen:$sh1,
+                           GPR:$rs2, uimmlog2xlen:$sh2),
+          (fake_node (SLLI (SH1ADD GPR:$rs1, GPR:$rs2),
+                            (TrailingZerosXForm uimmlog2xlen:$sh2)),
+                     uimmlog2xlen:$sh1)>;




Ben Shi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210913/1f207bdc/attachment.html>


More information about the llvm-dev mailing list