[llvm] [DAGCombiner] Preserve nuw when converting mul to shl. Use nuw in srl+shl combine. (PR #155043)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 18:13:30 PDT 2025


================
@@ -11094,6 +11097,11 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
   if (N0.getOpcode() == ISD::SHL &&
       (N0.getOperand(1) == N1 || N0->hasOneUse()) &&
       TLI.shouldFoldConstantShiftPairToMask(N, Level)) {
+    // If the shift amounts are the same and the shl doesn't shift out any
+    // non-zero bits, we can return the shl input.
+    if (N0.getOperand(1) == N1 && N0->getFlags().hasNoUnsignedWrap())
+      return N0.getOperand(0);
----------------
arsenm wrote:

If you're dropping the whole operation, should this be hoisted above the above profitability checks? 

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


More information about the llvm-commits mailing list