Skip to content

Commit 6cfe6a6

Browse files
author
Georgi Mirazchiyski
authored
[NFC][AMDGPU] Assert no bad shift operations will happen (#108416)
The assumption in the asserts is based on the fact that no SGPR/VGPR register Arg mask in the ISelLowering and Legalizer can equal zero. They are implicitly set to ~0 by default (meaning non-masked) or explicitly to a non-zero value. The `optimizeCompareInstr` case is different from the above described. It requires the mask to be a power-of-two because it's a special-case optimization, hence in this case we still cannot have an invalid shift. This commit also silences static analysis tools wrt potential bad shifts that could result from the output of `countr_zero(Mask)`.
1 parent 3d34053 commit 6cfe6a6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUArgumentUsageInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ struct ArgDescriptor {
7777
}
7878

7979
unsigned getMask() const {
80+
// None of the target SGPRs or VGPRs are expected to have a 'zero' mask.
81+
assert(Mask && "Invalid mask.");
8082
return Mask;
8183
}
8284

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9791,6 +9791,9 @@ bool SIInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
97919791
else
97929792
return false;
97939793

9794+
// A valid Mask is required to have a single bit set, hence a non-zero and
9795+
// power-of-two value. This verifies that we will not do 64-bit shift below.
9796+
assert(llvm::has_single_bit(Mask) && "Invalid mask.");
97949797
unsigned BitNo = llvm::countr_zero((uint64_t)Mask);
97959798
if (IsSigned && BitNo == SrcSize - 1)
97969799
return false;

0 commit comments

Comments
 (0)