[llvm] [X86] Remove redundant TEST after shifts when count is non-zero (PR #169069)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 24 13:48:41 PST 2025


================
@@ -23625,6 +23625,56 @@ static SDValue EmitTest(SDValue Op, X86::CondCode X86CC, const SDLoc &dl,
     return DAG.getNode(X86ISD::SUB, dl, VTs, Op->getOperand(0),
                        Op->getOperand(1)).getValue(1);
   }
+  case ISD::SHL:
+  case ISD::SRL:
+  case ISD::SRA: {
+    SDValue Amt = ArithOp.getOperand(1);
+
+    // Skip Constants
+    if (isa<ConstantSDNode>(Amt))
+      break;
+
+    // If optimising for size and can guarantee the shift amt is never zero
+    // the test.
+    bool OptForSize = DAG.getMachineFunction().getFunction().hasOptSize();
+    if (OptForSize && DAG.isKnownNeverZero(Amt)) {
----------------
GrumpyPigSkin wrote:

Updated

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


More information about the llvm-commits mailing list