Skip to content

Commit cc5eba1

Browse files
ritter-x2aarsenm
andauthored
[AMDGPU] Reject misaligned SGPR constraints for inline asm (llvm#123590)
The indices of SGPR register pairs need to be 2-aligned and SGPR quadruplets need to be 4-aligned. With this patch, we report an error when inline asm register constraints specify a misaligned register index, instead of silently dropping the specified index. Fixes llvm#123208 --------- Co-authored-by: Matt Arsenault <[email protected]>
1 parent fcec875 commit cc5eba1

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15877,6 +15877,12 @@ SITargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI_,
1587715877
RC = TRI->getAGPRClassForBitWidth(Width);
1587815878
if (RC) {
1587915879
Reg = TRI->getMatchingSuperReg(Reg, AMDGPU::sub0, RC);
15880+
if (!Reg) {
15881+
// The register class does not contain the requested register,
15882+
// e.g., because it is an SGPR pair that would violate alignment
15883+
// requirements.
15884+
return std::pair(0U, nullptr);
15885+
}
1588015886
return std::pair(Reg, RC);
1588115887
}
1588215888
}

llvm/test/CodeGen/AMDGPU/inlineasm-mismatched-size-error.ll

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,54 @@ define <2 x i8> @inline_asm_2xi8_in_s_def() {
102102
%r = and <2 x i8> %phys, %virt
103103
ret <2 x i8> %r
104104
}
105+
106+
107+
; The register is wide enough, but it does not satisfy alignment constraints:
108+
109+
; ERR: error: couldn't allocate input reg for constraint '{s[1:2]}'
110+
define void @misaligned_sgpr_2xi32_in(<2 x i32> inreg %arg0) {
111+
call void asm sideeffect "; use $0", "{s[1:2]}"(<2 x i32> %arg0)
112+
ret void
113+
}
114+
115+
; ERR: error: couldn't allocate input reg for constraint '{s[23:24]}'
116+
define void @misaligned_sgpr_2xi32_in_23(<2 x i32> inreg %arg0) {
117+
call void asm sideeffect "; use $0", "{s[23:24]}"(<2 x i32> %arg0)
118+
ret void
119+
}
120+
121+
; ERR: error: couldn't allocate input reg for constraint '{s[1:4]}'
122+
define void @misaligned_sgpr_4xi32_in(<4 x i32> inreg %arg0) {
123+
call void asm sideeffect "; use $0", "{s[1:4]}"(<4 x i32> %arg0)
124+
ret void
125+
}
126+
127+
; ERR: error: couldn't allocate input reg for constraint '{s[2:5]}'
128+
define void @misaligned_sgpr_4xi32_in_2(<4 x i32> inreg %arg0) {
129+
call void asm sideeffect "; use $0", "{s[2:5]}"(<4 x i32> %arg0)
130+
ret void
131+
}
132+
133+
; ERR: error: couldn't allocate output register for constraint '{s[1:2]}'
134+
define <2 x i32> @misaligned_sgpr_2xi32_out() {
135+
%asm = call <2 x i32> asm sideeffect "; def $0", "={s[1:2]}"()
136+
ret <2 x i32> %asm
137+
}
138+
139+
; ERR: error: couldn't allocate output register for constraint '{s[23:24]}'
140+
define <2 x i32> @misaligned_sgpr_2xi32_out_23() {
141+
%asm = call <2 x i32> asm sideeffect "; def $0", "={s[23:24]}"()
142+
ret <2 x i32> %asm
143+
}
144+
145+
; ERR: error: couldn't allocate output register for constraint '{s[1:4]}'
146+
define <4 x i32> @misaligned_sgpr_4xi32_out() {
147+
%asm = call <4 x i32> asm sideeffect "; def $0", "={s[1:4]}"()
148+
ret <4 x i32> %asm
149+
}
150+
151+
; ERR: error: couldn't allocate output register for constraint '{s[2:5]}'
152+
define <4 x i32> @misaligned_sgpr_4xi32_out_2() {
153+
%asm = call <4 x i32> asm sideeffect "; def $0", "={s[2:5]}"()
154+
ret <4 x i32> %asm
155+
}

0 commit comments

Comments
 (0)