[PATCH] D155344: [RISCV] Generalize 'tryFoldSelectIntOp` to other operations.

Mikhail Gudim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 10:12:56 PDT 2023


mgudim updated this revision to Diff 541114.
mgudim added a comment.

removed FADD and FSUB
removed the test, it will be commited in a separate patch


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

https://reviews.llvm.org/D155344

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp


Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -12260,12 +12260,19 @@
                                    SDValue TrueVal, SDValue FalseVal,
                                    bool Swapped) {
   bool Commutative = true;
+  bool AllOnesIsIdentity = false;
   switch (TrueVal.getOpcode()) {
   default:
     return SDValue();
+  case ISD::SHL:
+  case ISD::SRA:
+  case ISD::SRL:
   case ISD::SUB:
     Commutative = false;
     break;
+  case ISD::AND:
+    AllOnesIsIdentity = true;
+    break;
   case ISD::ADD:
   case ISD::OR:
   case ISD::XOR:
@@ -12285,12 +12292,15 @@
 
   EVT VT = N->getValueType(0);
   SDLoc DL(N);
-  SDValue Zero = DAG.getConstant(0, DL, VT);
   SDValue OtherOp = TrueVal.getOperand(1 - OpToFold);
+  EVT OtherOpVT = OtherOp->getValueType(0);
+  SDValue IdentityOperand = OtherOpVT.isFloatingPoint() ?
+    DAG.getConstantFP(0.0, DL, OtherOpVT) :
+    AllOnesIsIdentity ? DAG.getAllOnesConstant(DL, OtherOpVT) : DAG.getConstant(0, DL, OtherOpVT);
 
   if (Swapped)
-    std::swap(OtherOp, Zero);
-  SDValue NewSel = DAG.getSelect(DL, VT, N->getOperand(0), OtherOp, Zero);
+    std::swap(OtherOp, IdentityOperand);
+  SDValue NewSel = DAG.getSelect(DL, OtherOpVT, N->getOperand(0), OtherOp, IdentityOperand);
   return DAG.getNode(TrueVal.getOpcode(), DL, VT, FalseVal, NewSel);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155344.541114.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230717/6af9a687/attachment.bin>


More information about the llvm-commits mailing list