Skip to content

Commit a20220d

Browse files
committed
[AlwaysInliner] Call mergeAttributesForInlining after inlining
Like inlineCallIfPossible and InlinerPass, after inlining mergeAttributesForInlining should be called to merge callee's attributes to caller. But it is not called in AlwaysInliner, causes caller's attributes inconsistent with inlined code. Attached test case demonstrates that attribute "min-legal-vector-width"="512" is not merged into caller without this patch, and it causes failure in SelectionDAG when lowering the inlined AVX512 intrinsic. Differential Revision: https://reviews.llvm.org/D91446
1 parent bafa934 commit a20220d

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

llvm/lib/Transforms/IPO/AlwaysInliner.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
7878
*CB, IFI, &FAM.getResult<AAManager>(F), InsertLifetime);
7979
assert(Res.isSuccess() && "unexpected failure to inline");
8080
(void)Res;
81+
82+
// Merge the attributes based on the inlining.
83+
AttributeFuncs::mergeAttributesForInlining(*Caller, F);
84+
8185
Changed = true;
8286
}
8387

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: opt -passes=always-inline -S < %s | FileCheck %s
2+
3+
4+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-grtev4-linux-gnu"
6+
7+
; After AlwaysInline the callee's attributes should be merged into caller's attibutes.
8+
9+
; CHECK: define dso_local <2 x i64> @foo(<8 x i64>* byval(<8 x i64>) align 64 %0) #0
10+
; CHECK: attributes #0 = { uwtable mustprogress "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="512"
11+
12+
; Function Attrs: uwtable mustprogress
13+
define dso_local <2 x i64> @foo(<8 x i64>* byval(<8 x i64>) align 64 %0) #0 {
14+
entry:
15+
%kBias.addr = alloca <8 x i64>, align 64
16+
%indirect-arg-temp = alloca <8 x i64>, align 64
17+
%kBias = load <8 x i64>, <8 x i64>* %0, align 64, !tbaa !2
18+
store <8 x i64> %kBias, <8 x i64>* %kBias.addr, align 64, !tbaa !2
19+
%1 = load <8 x i64>, <8 x i64>* %kBias.addr, align 64, !tbaa !2
20+
store <8 x i64> %1, <8 x i64>* %indirect-arg-temp, align 64, !tbaa !2
21+
%call = call <2 x i64> @bar(<8 x i64>* byval(<8 x i64>) align 64 %indirect-arg-temp)
22+
ret <2 x i64> %call
23+
}
24+
25+
; Function Attrs: alwaysinline nounwind uwtable mustprogress
26+
define internal <2 x i64> @bar(<8 x i64>* byval(<8 x i64>) align 64 %0) #1 {
27+
entry:
28+
%__A.addr = alloca <8 x i64>, align 64
29+
%__A = load <8 x i64>, <8 x i64>* %0, align 64, !tbaa !2
30+
store <8 x i64> %__A, <8 x i64>* %__A.addr, align 64, !tbaa !2
31+
%1 = load <8 x i64>, <8 x i64>* %__A.addr, align 64, !tbaa !2
32+
%2 = bitcast <8 x i64> %1 to <16 x i32>
33+
%3 = call <16 x i8> @llvm.x86.avx512.mask.pmovs.db.512(<16 x i32> %2, <16 x i8> zeroinitializer, i16 -1)
34+
%4 = bitcast <16 x i8> %3 to <2 x i64>
35+
ret <2 x i64> %4
36+
}
37+
38+
; Function Attrs: nounwind readnone
39+
declare <16 x i8> @llvm.x86.avx512.mask.pmovs.db.512(<16 x i32>, <16 x i8>, i16) #2
40+
41+
attributes #0 = { uwtable mustprogress "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="128" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "prefer-vector-width"="128" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+aes,+avx,+avx2,+avx512bw,+avx512dq,+avx512f,+avx512vl,+bmi2,+cx16,+cx8,+f16c,+fma,+fxsr,+mmx,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
42+
attributes #1 = { alwaysinline nounwind uwtable mustprogress "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="512" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "prefer-vector-width"="128" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+aes,+avx,+avx2,+avx512f,+cx16,+cx8,+f16c,+fma,+fxsr,+mmx,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
43+
attributes #2 = { nounwind readnone }
44+
45+
46+
!2 = !{!3, !3, i64 0}
47+
!3 = !{!"omnipotent char", !4, i64 0}
48+
!4 = !{!"Simple C++ TBAA"}

0 commit comments

Comments
 (0)