[llvm] [X86] Avoid shl->mul lowbit-isolate fold on Zen when unprofitable (PR #217776)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 02:11:57 PDT 2026


================
@@ -50792,6 +50794,25 @@ static SDValue combineMul(SDNode *N, SelectionDAG &DAG,
   if (SDValue V = combineMulToPMADD52(N, DL, DAG, Subtarget))
     return V;
 
+  // #214517 folds shl X, cttz(Y) into mul(and(neg(Y), Y), X), which is
+  // usually profitable but is worse on some Zen microarchitectures: the mul
+  // form lowers to blsi+imul while the shl form lowers to tzcnt+shlx, which
+  // has better latency/throughput despite matching instruction count
+  // (https://github.com/llvm/llvm-project/issues/216550). Reverse the fold
+  // when the target prefers it. Only valid when Y is provably nonzero:
+  // CTTZ_ZERO_POISON is poison at Y == 0, while the mul form is
+  // well-defined (0) at Y == 0 - so the rewrite would be a miscompile for
+  // Y == 0 without that guard.
+  if (Subtarget.preferShlOverBlsiMul()) {
----------------
RKSimon wrote:

Missing type limits

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


More information about the llvm-commits mailing list