[PATCH] D108916: [RISCV] Optimize (add (shl x, c0), (shl y, c1)) with SH*ADD

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 30 09:00:31 PDT 2021


craig.topper added inline comments.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:5790
+  int64_t C1 = NC1->getSExtValue();
+  assert(C0 > 0 && C1 > 0 && "unexpected left shift amount");
+
----------------
You can't depend on this. I believe the add node will be visited before the shift nodes are visited to replace any negative shift amounts with undef. So if the IR contains a negative shift amount I think you will fail this assertion.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:6226
+    SDValue NA = transformAddShlImm(N, DAG, Subtarget);
+    if (NA.getNode() != nullptr)
+      return NA;
----------------
You can just check 

```
if (NA)
```

SDValue operator bool() checks getNode() != nullptr.


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

https://reviews.llvm.org/D108916



More information about the llvm-commits mailing list