[llvm] [DAG] SimplifyDemandedBits - fold FSHR(X, Y, Amt) -> SRL(Y, Amt) (PR #182294)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 08:11:35 PST 2026


================
@@ -2256,6 +2256,23 @@ bool TargetLowering::SimplifyDemandedBits(
       }
     }
 
+    // Fold FSHR(Op0,Op1,Op2) -> SRL(Op1,Op2)
+    // iff we're guaranteed not to use Op0.
+    // TODO: Add FSHL equivalent?
+    if (!IsFSHL && !DemandedBits.isAllOnes() &&
+        (!TLO.LegalOperations() || isOperationLegal(ISD::SRL, VT))) {
+      uint64_t MaxShiftAmt = BitWidth - 1; // urem(Op2, BitWidth)
----------------
RKSimon wrote:

Actually, just realised this isn't safe unless the shift amount is in bounds - hang on

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


More information about the llvm-commits mailing list