[all-commits] [llvm/llvm-project] 1416b5: [AMDGPU][DAGCombiner] Fix UADDO/USUBO_CARRY carry-...
Wooseok Lee via All-commits
all-commits at lists.llvm.org
Tue Jun 23 06:22:41 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 1416b5f6de966f29e6b9c4f868c330e693ce8952
https://github.com/llvm/llvm-project/commit/1416b5f6de966f29e6b9c4f868c330e693ce8952
Author: Wooseok Lee <wolee at amd.com>
Date: 2026-06-23 (Tue, 23 Jun 2026)
Changed paths:
M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
M llvm/lib/Target/AMDGPU/SIISelLowering.cpp
M llvm/lib/Target/AMDGPU/SIISelLowering.h
M llvm/test/CodeGen/AMDGPU/uaddo.ll
M llvm/test/CodeGen/AMDGPU/usubo.ll
Log Message:
-----------
[AMDGPU][DAGCombiner] Fix UADDO/USUBO_CARRY carry-out miscompile and remove redundant AMDGPU combine (#204362)
performAddCarrySubCarryCombine in SIISelLowering folded:
uaddo_carry((x+y), 0, cc) -> uaddo_carry(x, y, cc)
usubo_carry((x-y), 0, cc) -> usubo_carry(x, y, cc)
Both produce the same value but differ in carry-out when x+y (or x-y)
wraps. The fold was missing a !N->hasAnyUseOfValue(1) guard, giving
wrong carry values to consumers. E.g. x=0xFFFFFFFF, y=1, cc=0:
original: ((x+y) mod 2^32 + cc) >= 2^32 = 0 (correct)
folded: (x+y+cc) >= 2^32 = 1 (wrong)
The generic visitUADDO_CARRY (DAGCombiner.cpp) already handles
the UADDO_CARRY/ADD fold with the correct guard. Since target combines
fire before generic ones, the AMDGPU ADD arm was a buggy duplicate.
The USUBO_CARRY/SUB arm is produced by AMDGPU's performAddCombine
which converts add(sub(v,a), sext(cmp)) -> usubo_carry(sub(v,a), 0,
cmp).
There was no generic equivalent for this pattern.
Fix by adding the symmetric fold to visitUSUBO_CARRY:
(usubo_carry (sub X, Y), 0, Carry) -> (usubo_carry X, Y, Carry)
with the same guard, then removing performAddCarrySubCarryCombine
from SIISelLowering entirely as it is now fully subsumed.
Tests: Add AMDGPU tests in uaddo.ll and usubo.ll covering the
carry-out-used (fold suppressed) and carry-out-unused (fold applied)
cases, autogenerated with update_llc_test_checks.py.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list