[llvm] [DAGCombine] Propagate truncate to operands (PR #98666)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 02:38:20 PDT 2024


================
@@ -15198,6 +15202,25 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
     break;
   }
 
+  if (TLI.shouldReduceRegisterPressure()) {
+    switch (N0.getOpcode()) {
+    case ISD::ADD:
+    case ISD::SUB:
+    case ISD::MUL:
+    case ISD::AND:
+    case ISD::OR:
+    case ISD::XOR:
+      if (!(N0.hasOneUse() && VT.isScalarInteger() &&
+            TLI.isTruncateFree(SrcVT, VT)))
+        break;
+      if (LegalOperations && !TLI.isOperationLegal(N0.getOpcode(), VT))
+        break;
+      SDValue NarrowL = DAG.getNode(ISD::TRUNCATE, DL, VT, N0.getOperand(0));
+      SDValue NarrowR = DAG.getNode(ISD::TRUNCATE, DL, VT, N0.getOperand(1));
+      return DAG.getNode(N0.getOpcode(), DL, VT, NarrowL, NarrowR);
+    }
+  }
----------------
RKSimon wrote:

We already do this in the switch immediately above - why not just add the shouldReduceRegisterPressure test to the existing condition logic?

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


More information about the llvm-commits mailing list