[llvm] [X86] SimplifyDemandedBitsForTargetNode - add X86ISD::BZHI handling (PR #199828)

Qiongsi Wu via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 17:49:31 PDT 2026


================
@@ -46027,6 +46027,68 @@ bool X86TargetLowering::SimplifyDemandedBitsForTargetNode(
 
     break;
   }
+  case X86ISD::BZHI: {
+    SDValue Op0 = Op.getOperand(0);
+    SDValue Op1 = Op.getOperand(1);
+
+    // If the index's max value is less than BitWidth, bits above it
+    // are not demanded from the source.
+    auto SimplifySrcDemandedBits = [&](uint64_t MaxIdx) -> bool {
+      if (MaxIdx < BitWidth) {
+        APInt DemandedSrc =
+            OriginalDemandedBits & APInt::getLowBitsSet(BitWidth, MaxIdx);
+        if (SimplifyDemandedBits(Op0, DemandedSrc, Known, TLO, Depth + 1))
+          return true;
+      }
+      return false;
+    };
+
+    if (auto *Cst1 = dyn_cast<ConstantSDNode>(Op1)) {
----------------
qiongsiwu wrote:

Good point! Thanks! I thought about it and rewrote this section. I also don't think I need the `Known` calculations so I removed them as well. What do you think? 

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


More information about the llvm-commits mailing list