Skip to content

Commit 1c7f323

Browse files
committed
[TargetLowering] Only inspect attributes in the arguments for ArgListEntry
Parameter attributes are considered part of the function [1], and like mismatched calling conventions [2], we can't have the verifier check for mismatched parameter attributes. This is a reland after fixing MSan issues in D102667. [1] https://llvm.org/docs/LangRef.html#parameter-attributes [2] https://llvm.org/docs/FAQ.html#why-does-instcombine-simplifycfg-turn-a-call-to-a-function-with-a-mismatched-calling-convention-into-unreachable-why-not-make-the-verifier-reject-it Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D101806
1 parent b86302e commit 1c7f323

23 files changed

+185
-129
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Changes to the LLVM IR
6464
* The opaque pointer type ``ptr`` has been introduced. It is still in the
6565
process of being worked on and should not be used yet.
6666

67+
=======
6768
Changes to building LLVM
6869
------------------------
6970

@@ -74,6 +75,13 @@ Changes to building LLVM
7475
Changes to TableGen
7576
-------------------
7677

78+
Changes to Backend Code Generation
79+
----------------------------------
80+
81+
* When lowering calls, only ABI attributes on the call itself are checked, not
82+
the caller. Frontends need to make sure to properly set ABI attributes on
83+
calls (and always should have).
84+
7785
Changes to the ARM Backend
7886
--------------------------
7987

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,32 @@ bool TargetLowering::parametersInCSRMatch(const MachineRegisterInfo &MRI,
102102
return true;
103103
}
104104

105-
/// Set CallLoweringInfo attribute flags based on a call instruction
106-
/// and called function attributes.
105+
/// Set CallLoweringInfo attribute flags based on the call instruction's
106+
/// argument attributes.
107107
void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
108108
unsigned ArgIdx) {
109-
IsSExt = Call->paramHasAttr(ArgIdx, Attribute::SExt);
110-
IsZExt = Call->paramHasAttr(ArgIdx, Attribute::ZExt);
111-
IsInReg = Call->paramHasAttr(ArgIdx, Attribute::InReg);
112-
IsSRet = Call->paramHasAttr(ArgIdx, Attribute::StructRet);
113-
IsNest = Call->paramHasAttr(ArgIdx, Attribute::Nest);
114-
IsByVal = Call->paramHasAttr(ArgIdx, Attribute::ByVal);
115-
IsPreallocated = Call->paramHasAttr(ArgIdx, Attribute::Preallocated);
116-
IsInAlloca = Call->paramHasAttr(ArgIdx, Attribute::InAlloca);
117-
IsReturned = Call->paramHasAttr(ArgIdx, Attribute::Returned);
118-
IsSwiftSelf = Call->paramHasAttr(ArgIdx, Attribute::SwiftSelf);
119-
IsSwiftAsync = Call->paramHasAttr(ArgIdx, Attribute::SwiftAsync);
120-
IsSwiftError = Call->paramHasAttr(ArgIdx, Attribute::SwiftError);
121-
Alignment = Call->getParamStackAlign(ArgIdx);
109+
auto Attrs = Call->getAttributes();
110+
111+
IsSExt = Attrs.hasParamAttribute(ArgIdx, Attribute::SExt);
112+
IsZExt = Attrs.hasParamAttribute(ArgIdx, Attribute::ZExt);
113+
IsInReg = Attrs.hasParamAttribute(ArgIdx, Attribute::InReg);
114+
IsSRet = Attrs.hasParamAttribute(ArgIdx, Attribute::StructRet);
115+
IsNest = Attrs.hasParamAttribute(ArgIdx, Attribute::Nest);
116+
IsReturned = Attrs.hasParamAttribute(ArgIdx, Attribute::Returned);
117+
IsSwiftSelf = Attrs.hasParamAttribute(ArgIdx, Attribute::SwiftSelf);
118+
IsSwiftAsync = Attrs.hasParamAttribute(ArgIdx, Attribute::SwiftAsync);
119+
IsSwiftError = Attrs.hasParamAttribute(ArgIdx, Attribute::SwiftError);
120+
Alignment = Attrs.getParamStackAlignment(ArgIdx);
121+
122+
IsByVal = Attrs.hasParamAttribute(ArgIdx, Attribute::ByVal);
122123
ByValType = nullptr;
123124
if (IsByVal) {
124125
ByValType = Call->getParamByValType(ArgIdx);
125126
if (!Alignment)
126127
Alignment = Call->getParamAlign(ArgIdx);
127128
}
129+
IsInAlloca = Attrs.hasParamAttribute(ArgIdx, Attribute::InAlloca);
130+
IsPreallocated = Attrs.hasParamAttribute(ArgIdx, Attribute::Preallocated);
128131
PreallocatedType = nullptr;
129132
if (IsPreallocated)
130133
PreallocatedType = Call->getParamPreallocatedType(ArgIdx);

llvm/test/CodeGen/AArch64/arm64-this-return.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ entry:
3838
; CHECK-NOT: mov x0, {{x[0-9]+}}
3939
; CHECK: b {{_?B_ctor_base}}
4040
%0 = bitcast %struct.C* %this to %struct.A*
41-
%call = tail call %struct.A* @A_ctor_base(%struct.A* %0)
41+
%call = tail call %struct.A* @A_ctor_base(%struct.A* returned %0)
4242
%1 = getelementptr inbounds %struct.C, %struct.C* %this, i32 0, i32 0
43-
%call2 = tail call %struct.B* @B_ctor_base(%struct.B* %1, i32 %x)
43+
%call2 = tail call %struct.B* @B_ctor_base(%struct.B* returned %1, i32 %x)
4444
ret %struct.C* %this
4545
}
4646

@@ -88,7 +88,7 @@ define %struct.C* @C_ctor_complete(%struct.C* %this, i32 %x) {
8888
entry:
8989
; CHECK-LABEL: C_ctor_complete:
9090
; CHECK: b {{_?C_ctor_base}}
91-
%call = tail call %struct.C* @C_ctor_base(%struct.C* %this, i32 %x)
91+
%call = tail call %struct.C* @C_ctor_base(%struct.C* returned %this, i32 %x)
9292
ret %struct.C* %this
9393
}
9494

@@ -135,8 +135,8 @@ entry:
135135
; CHECK-NOT: mov x0, {{x[0-9]+}}
136136
; CHECK: b {{_?B_ctor_complete}}
137137
%b = getelementptr inbounds %struct.D, %struct.D* %this, i32 0, i32 0
138-
%call = tail call %struct.B* @B_ctor_complete(%struct.B* %b, i32 %x)
139-
%call2 = tail call %struct.B* @B_ctor_complete(%struct.B* %b, i32 %x)
138+
%call = tail call %struct.B* @B_ctor_complete(%struct.B* returned %b, i32 %x)
139+
%call2 = tail call %struct.B* @B_ctor_complete(%struct.B* returned %b, i32 %x)
140140
ret %struct.D* %this
141141
}
142142

@@ -166,8 +166,8 @@ entry:
166166
; CHECK-LABEL: E_ctor_base:
167167
; CHECK-NOT: b {{_?B_ctor_complete}}
168168
%b = getelementptr inbounds %struct.E, %struct.E* %this, i32 0, i32 0
169-
%call = tail call %struct.B* @B_ctor_complete(%struct.B* %b, i32 %x)
169+
%call = tail call %struct.B* @B_ctor_complete(%struct.B* returned %b, i32 %x)
170170
%b2 = getelementptr inbounds %struct.E, %struct.E* %this, i32 0, i32 1
171-
%call2 = tail call %struct.B* @B_ctor_complete(%struct.B* %b2, i32 %x)
171+
%call2 = tail call %struct.B* @B_ctor_complete(%struct.B* returned %b2, i32 %x)
172172
ret %struct.E* %this
173173
}

llvm/test/CodeGen/AArch64/bitfield-extract.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ define signext i16 @test10(i64 %a) {
9191
define void @test11(i64 %a) {
9292
%tmp = lshr i64 %a, 23
9393
%res = trunc i64 %tmp to i16
94-
call void @use(i16 %res, i64 %tmp)
94+
call void @use(i16 signext %res, i64 %tmp)
9595
ret void
9696
}
9797

llvm/test/CodeGen/AArch64/tailcall-explicit-sret.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare void @test_explicit_sret(i1024* sret(i1024)) #0
1111
; CHECK-LABEL: _test_tailcall_explicit_sret:
1212
; CHECK-NEXT: b _test_explicit_sret
1313
define void @test_tailcall_explicit_sret(i1024* sret(i1024) %arg) #0 {
14-
tail call void @test_explicit_sret(i1024* %arg)
14+
tail call void @test_explicit_sret(i1024* sret(i1024) %arg)
1515
ret void
1616
}
1717

@@ -20,7 +20,7 @@ define void @test_tailcall_explicit_sret(i1024* sret(i1024) %arg) #0 {
2020
; CHECK: bl _test_explicit_sret
2121
; CHECK: ret
2222
define void @test_call_explicit_sret(i1024* sret(i1024) %arg) #0 {
23-
call void @test_explicit_sret(i1024* %arg)
23+
call void @test_explicit_sret(i1024* sret(i1024) %arg)
2424
ret void
2525
}
2626

@@ -30,7 +30,7 @@ define void @test_call_explicit_sret(i1024* sret(i1024) %arg) #0 {
3030
; CHECK: ret
3131
define void @test_tailcall_explicit_sret_alloca_unused() #0 {
3232
%l = alloca i1024, align 8
33-
tail call void @test_explicit_sret(i1024* %l)
33+
tail call void @test_explicit_sret(i1024* sret(i1024) %l)
3434
ret void
3535
}
3636

@@ -44,7 +44,7 @@ define void @test_tailcall_explicit_sret_alloca_dummyusers(i1024* %ptr) #0 {
4444
%l = alloca i1024, align 8
4545
%r = load i1024, i1024* %ptr, align 8
4646
store i1024 %r, i1024* %l, align 8
47-
tail call void @test_explicit_sret(i1024* %l)
47+
tail call void @test_explicit_sret(i1024* sret(i1024) %l)
4848
ret void
4949
}
5050

@@ -56,7 +56,7 @@ define void @test_tailcall_explicit_sret_alloca_dummyusers(i1024* %ptr) #0 {
5656
; CHECK: ret
5757
define void @test_tailcall_explicit_sret_gep(i1024* %ptr) #0 {
5858
%ptr2 = getelementptr i1024, i1024* %ptr, i32 1
59-
tail call void @test_explicit_sret(i1024* %ptr2)
59+
tail call void @test_explicit_sret(i1024* sret(i1024) %ptr2)
6060
ret void
6161
}
6262

@@ -69,7 +69,7 @@ define void @test_tailcall_explicit_sret_gep(i1024* %ptr) #0 {
6969
; CHECK: ret
7070
define i1024 @test_tailcall_explicit_sret_alloca_returned() #0 {
7171
%l = alloca i1024, align 8
72-
tail call void @test_explicit_sret(i1024* %l)
72+
tail call void @test_explicit_sret(i1024* sret(i1024) %l)
7373
%r = load i1024, i1024* %l, align 8
7474
ret i1024 %r
7575
}

llvm/test/CodeGen/AMDGPU/call-argument-types.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ define amdgpu_kernel void @test_call_external_void_func_i1_imm() #0 {
9292
; GCN-NEXT: s_endpgm
9393
define amdgpu_kernel void @test_call_external_void_func_i1_signext(i32) #0 {
9494
%var = load volatile i1, i1 addrspace(1)* undef
95-
call void @external_void_func_i1_signext(i1 %var)
95+
call void @external_void_func_i1_signext(i1 signext %var)
9696
ret void
9797
}
9898

@@ -113,7 +113,7 @@ define amdgpu_kernel void @test_call_external_void_func_i1_signext(i32) #0 {
113113
; GCN-NEXT: s_endpgm
114114
define amdgpu_kernel void @test_call_external_void_func_i1_zeroext(i32) #0 {
115115
%var = load volatile i1, i1 addrspace(1)* undef
116-
call void @external_void_func_i1_zeroext(i1 %var)
116+
call void @external_void_func_i1_zeroext(i1 zeroext %var)
117117
ret void
118118
}
119119

@@ -148,7 +148,7 @@ define amdgpu_kernel void @test_call_external_void_func_i8_imm(i32) #0 {
148148
; GCN-NEXT: s_endpgm
149149
define amdgpu_kernel void @test_call_external_void_func_i8_signext(i32) #0 {
150150
%var = load volatile i8, i8 addrspace(1)* undef
151-
call void @external_void_func_i8_signext(i8 %var)
151+
call void @external_void_func_i8_signext(i8 signext %var)
152152
ret void
153153
}
154154

@@ -166,7 +166,7 @@ define amdgpu_kernel void @test_call_external_void_func_i8_signext(i32) #0 {
166166
; GCN-NEXT: s_endpgm
167167
define amdgpu_kernel void @test_call_external_void_func_i8_zeroext(i32) #0 {
168168
%var = load volatile i8, i8 addrspace(1)* undef
169-
call void @external_void_func_i8_zeroext(i8 %var)
169+
call void @external_void_func_i8_zeroext(i8 zeroext %var)
170170
ret void
171171
}
172172

@@ -195,7 +195,7 @@ define amdgpu_kernel void @test_call_external_void_func_i16_imm() #0 {
195195
; GCN-NEXT: s_endpgm
196196
define amdgpu_kernel void @test_call_external_void_func_i16_signext(i32) #0 {
197197
%var = load volatile i16, i16 addrspace(1)* undef
198-
call void @external_void_func_i16_signext(i16 %var)
198+
call void @external_void_func_i16_signext(i16 signext %var)
199199
ret void
200200
}
201201

@@ -212,7 +212,7 @@ define amdgpu_kernel void @test_call_external_void_func_i16_signext(i32) #0 {
212212
; GCN-NEXT: s_endpgm
213213
define amdgpu_kernel void @test_call_external_void_func_i16_zeroext(i32) #0 {
214214
%var = load volatile i16, i16 addrspace(1)* undef
215-
call void @external_void_func_i16_zeroext(i16 %var)
215+
call void @external_void_func_i16_zeroext(i16 zeroext %var)
216216
ret void
217217
}
218218

llvm/test/CodeGen/AMDGPU/callee-special-input-vgprs-packed.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ define amdgpu_kernel void @kern_call_too_many_args_use_workitem_id_x_byval() #1
517517
i32 210, i32 220, i32 230, i32 240,
518518
i32 250, i32 260, i32 270, i32 280,
519519
i32 290, i32 300, i32 310, i32 320,
520-
i32 addrspace(5)* %alloca)
520+
i32 addrspace(5)* byval(i32) %alloca)
521521
ret void
522522
}
523523

@@ -541,7 +541,7 @@ define void @func_call_too_many_args_use_workitem_id_x_byval() #1 {
541541
i32 210, i32 220, i32 230, i32 240,
542542
i32 250, i32 260, i32 270, i32 280,
543543
i32 290, i32 300, i32 310, i32 320,
544-
i32 addrspace(5)* %alloca)
544+
i32 addrspace(5)* byval(i32) %alloca)
545545
ret void
546546
}
547547

llvm/test/CodeGen/AMDGPU/callee-special-input-vgprs.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ define amdgpu_kernel void @kern_call_too_many_args_use_workitem_id_x_byval() #1
649649
i32 210, i32 220, i32 230, i32 240,
650650
i32 250, i32 260, i32 270, i32 280,
651651
i32 290, i32 300, i32 310, i32 320,
652-
i32 addrspace(5)* %alloca)
652+
i32 addrspace(5)* byval(i32) %alloca)
653653
ret void
654654
}
655655

@@ -686,7 +686,7 @@ define void @func_call_too_many_args_use_workitem_id_x_byval() #1 {
686686
i32 210, i32 220, i32 230, i32 240,
687687
i32 250, i32 260, i32 270, i32 280,
688688
i32 290, i32 300, i32 310, i32 320,
689-
i32 addrspace(5)* %alloca)
689+
i32 addrspace(5)* byval(i32) %alloca)
690690
ret void
691691
}
692692

0 commit comments

Comments
 (0)