[llvm] [AMDGPU] Keep divergent i64 mul feeding an add for the mad64 fold (PR #226963)
Pankaj Dwivedi via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 05:10:36 PDT 2026
================
@@ -1446,14 +1450,26 @@ bool AMDGPUCodeGenPrepareImpl::tryNarrowMathIfNoOverflow(Instruction *I) {
return true;
}
+// Mul24 or narrowing would hide the ISD::MUL that tryFoldToMad64_32 matches.
+bool AMDGPUCodeGenPrepareImpl::shouldKeepMulForMad64(
+ const BinaryOperator &I) const {
+ if (I.getOpcode() != Instruction::Mul || !I.getType()->isIntegerTy(64))
+ return false;
+ if (ST.getGeneration() < AMDGPUSubtarget::GFX9 || UA.isUniformAtDef(&I))
+ return false;
+ return I.hasOneUse() && match(I.user_back(), m_Add(m_Value(), m_Value()));
----------------
PankajDwivedi-25 wrote:
can we allow two add user which is already allowed in tryFoldToMad64_32? which would be folded in two mad.
also,
The skip here only looks for IR add. Address math is often:
> %mul = mul i64 %idx, %scale
> %p = getelementptr i8, ptr %base, i64 %mul
That is not add, so the skip does not fire? Can we also fold this, I am not sure.
https://github.com/llvm/llvm-project/pull/226963
More information about the llvm-commits
mailing list