[llvm] [DAG] Constant fold ISD::FSHL/FSHR nodes (PR #154480)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 00:50:01 PDT 2025


================
@@ -7175,6 +7175,49 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
     }
   }
 
+  // Handle fshl/fshr special cases.
+  if (Opcode == ISD::FSHL || Opcode == ISD::FSHR) {
+    auto *C1 = dyn_cast<ConstantSDNode>(Ops[0]);
+    auto *C2 = dyn_cast<ConstantSDNode>(Ops[1]);
+    auto *C3 = dyn_cast<ConstantSDNode>(Ops[2]);
+
+    if (C1 && C2 && C3) {
+      if (C1->isOpaque() || C2->isOpaque() || C3->isOpaque())
+        return SDValue();
+      const APInt V1 = C1->getAPIntValue(), V2 = C2->getAPIntValue(),
+                  V3 = C3->getAPIntValue();
----------------
arsenm wrote:

Don't need these temporary APInt copies, make const reference or just directly pull the gets into the APInt operand list below 

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


More information about the llvm-commits mailing list