[PATCH] D82262: [RISCV] Optimize addition with an immediate

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 7 15:49:26 PDT 2020


MaskRay added inline comments.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:80
+  case ISD::ADD: {
+    // The second operand must be an immediate.
+    if (auto *ConstOp = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
----------------
The two comments can be combined and placed under `case ISD::ADD:`

Optimize (add r, imm) to (addi (addi r, imm0) imm1) if applicable.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:83
+      // The immediate operand must not have other use.
+      if (!ConstOp->hasOneUse())
+        break;
----------------
`if (!ConstOp->hasOneUse())` is not tested.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:92
+      EVT VT = Node->getValueType(0);
+      SDValue ImmOp0 = CurDAG->getTargetConstant(Imm - Imm / 2, DL, VT);
+      SDValue ImmOp1 = CurDAG->getTargetConstant(Imm / 2, DL, VT);
----------------
Add const if applicable.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82262/new/

https://reviews.llvm.org/D82262





More information about the llvm-commits mailing list