[clang] [llvm] [llvm][NVPTX] Strip unneeded '+0' in PTX load/store (PR #113017)

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 19 00:02:27 PDT 2024


================
@@ -363,6 +363,14 @@ void NVPTXInstPrinter::printMemOperand(const MCInst *MI, int OpNum,
   }
 }
 
+void NVPTXInstPrinter::printOffseti32imm(const MCInst *MI, int OpNum,
+                                         raw_ostream &O, const char *Modifier) {
+  if (auto &Op = MI->getOperand(OpNum); Op.isImm() && Op.getImm() == 0)
+    return; // don't print '+0'
+  O << "+";
+  printOperand(MI, OpNum, O);
----------------
Artem-B wrote:

Nit: No need for the early return here. Also, instead of just ignoring non-immediate operands, we should probablly assert it, as that should never happen.

```
  auto &Op = MI->getOperand(OpNum); 
  assert(Op.isImm() && "Invalid operand");
  if (Op.getImm() != 0)) {
    O << "+";
    printOperand(MI, OpNum, O);
  }
```

https://github.com/llvm/llvm-project/pull/113017


More information about the cfe-commits mailing list