[PATCH] D133866: [SelectionDAG] Add helper function to check whether a SDValue is neutral element. NFC.

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 08:03:33 PDT 2022


RKSimon added a comment.

In D133866#3791129 <https://reviews.llvm.org/D133866#3791129>, @fakepaper56 wrote:

> I am not sure what is the compatibility issue. I think `foldSelectWithIdentityConstant` could be also used for operations which not have communicative property (e.g. div).

I#m sorry - compatibility was a poor word to use - my hope is that we can remove the 'isIdentityConstantForOpcode' lambda inside foldSelectWithIdentityConstant and use isNeutralConstant instead - either as part of this patch or a future patch.



================
Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:10738
 
+bool llvm::isNeutralConstant(unsigned Opcode, SDNodeFlags Flags, SDValue V) {
+  if (auto *Const = dyn_cast<ConstantSDNode>(V)) {
----------------
Can you add a OperandNo argument as well? It can default to 0 if necessary. This will allow us to handle sub/fsub, div/fdiv and shifts in future patches.

```
llvm::isNeutralConstant(unsigned Opcode, SDNodeFlags Flags, SDValue V, unsigned OperandNo = 0) 
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133866



More information about the llvm-commits mailing list