[llvm] [AMDGPU][GlobalISel] Fold zext(carry) into add/sub-with-carry (PR #224093)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 10:56:50 PDT 2026
================
@@ -393,6 +398,35 @@ bool AMDGPUPostLegalizerCombinerImpl::matchCombine_s_mul_u64(
return false;
}
+bool AMDGPUPostLegalizerCombinerImpl::isCarryOut(Register Reg) const {
+ const MachineInstr *Def = MRI.getVRegDef(Reg);
+ if (!Def)
+ return false;
+
+ switch (Def->getOpcode()) {
+ case TargetOpcode::G_UADDO:
+ case TargetOpcode::G_UADDE:
+ case TargetOpcode::G_USUBO:
+ case TargetOpcode::G_USUBE:
+ return Def->getOperand(1).getReg() == Reg;
+ default:
+ return false;
+ }
+}
+
+bool AMDGPUPostLegalizerCombinerImpl::shouldFoldCarryIntoAdd(
+ Register Src) const {
+ // Let right_identity_zero combine delete this instead.
+ if (mi_match(Src, MRI, m_SpecificICst(0)))
+ return false;
+
+ // When both operands are a carry only the right hand one is folded, so that
+ // the two carries never have to be live at the same time.
+ Register Carry;
+ return !(mi_match(Src, MRI, m_GZExt(m_Reg(Carry))) &&
----------------
arsenm wrote:
extra parens
https://github.com/llvm/llvm-project/pull/224093
More information about the llvm-commits
mailing list