[llvm] [AMDGPU] Select v_lshl_add_u32 instead of v_mul_lo_u32 by constant (PR #71035)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 2 01:28:25 PDT 2023


================
@@ -4080,6 +4080,17 @@ SDValue AMDGPUTargetLowering::performMulCombine(SDNode *N,
   SDValue N0 = N->getOperand(0);
   SDValue N1 = N->getOperand(1);
 
+  // FIXME: Probably should only be done for gfx9 and onward.
+  if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) {
+    APInt CVal = C->getAPIntValue();
+    if (isPowerOf2_32(CVal.getZExtValue() - 1)) {
+      unsigned int Sqr = Log2_32(CVal.getZExtValue() - 1);
+      SDValue Pow2Constant = DAG.getConstant(Sqr, DL, N1.getValueType());
+      SDValue Shl = DAG.getNode(ISD::SHL, DL, VT, N0, Pow2Constant);
+      return DAG.getNode(ISD::ADD, DL, VT, Shl, N0);
----------------
arsenm wrote:

Missing a type check?

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


More information about the llvm-commits mailing list