Skip to content

Commit 225b775

Browse files
Ahsan Saghirtstellar
authored andcommitted
[PowerPC] Prevent argument promotion of types with size greater than 128 bits
This patch prevents argument promotion of types having type size greater than 128 bits. Fixes Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=49952 Reviewed By: #powerpc, nemanjai Differential Revision: https://reviews.llvm.org/D101188 (cherry picked from commit 670736a)
1 parent ac593de commit 225b775

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,27 @@ unsigned PPCTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
12121212
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
12131213
}
12141214

1215+
bool PPCTTIImpl::areFunctionArgsABICompatible(
1216+
const Function *Caller, const Function *Callee,
1217+
SmallPtrSetImpl<Argument *> &Args) const {
1218+
1219+
// We need to ensure that argument promotion does not
1220+
// attempt to promote pointers to MMA types (__vector_pair
1221+
// and __vector_quad) since these types explicitly cannot be
1222+
// passed as arguments. Both of these types are larger than
1223+
// the 128-bit Altivec vectors and have a scalar size of 1 bit.
1224+
if (!BaseT::areFunctionArgsABICompatible(Caller, Callee, Args))
1225+
return false;
1226+
1227+
return llvm::none_of(Args, [](Argument *A) {
1228+
auto *EltTy = cast<PointerType>(A->getType())->getElementType();
1229+
if (EltTy->isSized())
1230+
return (EltTy->isIntOrIntVectorTy(1) &&
1231+
EltTy->getPrimitiveSizeInBits() > 128);
1232+
return false;
1233+
});
1234+
}
1235+
12151236
bool PPCTTIImpl::canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE,
12161237
LoopInfo *LI, DominatorTree *DT,
12171238
AssumptionCache *AC, TargetLibraryInfo *LibInfo) {

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
129129
unsigned getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
130130
TTI::TargetCostKind CostKind);
131131

132+
bool areFunctionArgsABICompatible(const Function *Caller,
133+
const Function *Callee,
134+
SmallPtrSetImpl<Argument *> &Args) const;
132135
/// @}
133136
};
134137

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -argpromotion -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
3+
; RUN: opt -S -passes=argpromotion -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
4+
5+
; Test to check that we do not promote arguments when the
6+
; type size is greater than 128 bits.
7+
8+
define internal fastcc void @print_acc(<512 x i1>* nocapture readonly %a) nounwind {
9+
; CHECK-LABEL: @print_acc(
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: [[TMP0:%.*]] = load <512 x i1>, <512 x i1>* [[A:%.*]], align 64
12+
; CHECK-NEXT: [[TMP1:%.*]] = tail call { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @llvm.ppc.mma.disassemble.acc(<512 x i1> [[TMP0]])
13+
; CHECK-NEXT: [[TMP2:%.*]] = extractvalue { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } [[TMP1]], 0
14+
; CHECK-NEXT: ret void
15+
;
16+
entry:
17+
%0 = load <512 x i1>, <512 x i1>* %a, align 64
18+
%1 = tail call { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @llvm.ppc.mma.disassemble.acc(<512 x i1> %0)
19+
%2 = extractvalue { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } %1, 0
20+
ret void
21+
}
22+
23+
declare { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @llvm.ppc.mma.disassemble.acc(<512 x i1>) nounwind
24+
25+
define dso_local void @test(<512 x i1>* nocapture %a, <16 x i8> %ac) {
26+
; CHECK-LABEL: @test(
27+
; CHECK-NEXT: entry:
28+
; CHECK-NEXT: [[TMP0:%.*]] = tail call <512 x i1> @llvm.ppc.mma.xvf32ger(<16 x i8> [[AC:%.*]], <16 x i8> [[AC]])
29+
; CHECK-NEXT: store <512 x i1> [[TMP0]], <512 x i1>* [[A:%.*]], align 64
30+
; CHECK-NEXT: tail call fastcc void @print_acc(<512 x i1>* nonnull [[A]])
31+
; CHECK-NEXT: ret void
32+
;
33+
entry:
34+
%0 = tail call <512 x i1> @llvm.ppc.mma.xvf32ger(<16 x i8> %ac, <16 x i8> %ac)
35+
store <512 x i1> %0, <512 x i1>* %a, align 64
36+
tail call fastcc void @print_acc(<512 x i1>* nonnull %a)
37+
ret void
38+
}
39+
40+
declare <512 x i1> @llvm.ppc.mma.xvf32ger(<16 x i8>, <16 x i8>) nounwind
41+
42+
@.str = private unnamed_addr constant [11 x i8] c"Vector: { \00", align 1
43+
@.str.1 = private unnamed_addr constant [5 x i8] c"%d, \00", align 1
44+
@.str.2 = private unnamed_addr constant [6 x i8] c"%d }\0A\00", align 1
45+
46+
define internal fastcc void @printWideVec(<16 x i32> %ptr.val) nounwind {
47+
; CHECK-LABEL: @printWideVec(
48+
; CHECK-NEXT: entry:
49+
; CHECK-NEXT: [[CALL:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
50+
; CHECK-NEXT: [[VECEXT:%.*]] = extractelement <16 x i32> [[PTR_VAL:%.*]], i32 0
51+
; CHECK-NEXT: [[CALL1:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT]])
52+
; CHECK-NEXT: [[VECEXT_1:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 1
53+
; CHECK-NEXT: [[CALL1_1:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT_1]])
54+
; CHECK-NEXT: [[VECEXT_2:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 2
55+
; CHECK-NEXT: [[CALL1_2:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT_2]])
56+
; CHECK-NEXT: [[VECEXT_3:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 3
57+
; CHECK-NEXT: [[CALL1_3:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT_3]])
58+
; CHECK-NEXT: [[VECEXT_4:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 4
59+
; CHECK-NEXT: [[CALL1_4:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT_4]])
60+
; CHECK-NEXT: [[VECEXT_5:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 5
61+
; CHECK-NEXT: [[CALL1_5:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT_5]])
62+
; CHECK-NEXT: [[VECEXT_6:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 6
63+
; CHECK-NEXT: [[CALL1_6:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext [[VECEXT_6]])
64+
; CHECK-NEXT: [[VECEXT2:%.*]] = extractelement <16 x i32> [[PTR_VAL]], i32 7
65+
; CHECK-NEXT: [[CALL3:%.*]] = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 signext [[VECEXT2]])
66+
; CHECK-NEXT: ret void
67+
;
68+
entry:
69+
%call = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
70+
%vecext = extractelement <16 x i32> %ptr.val, i32 0
71+
%call1 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext)
72+
%vecext.1 = extractelement <16 x i32> %ptr.val, i32 1
73+
%call1.1 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext.1)
74+
%vecext.2 = extractelement <16 x i32> %ptr.val, i32 2
75+
%call1.2 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext.2)
76+
%vecext.3 = extractelement <16 x i32> %ptr.val, i32 3
77+
%call1.3 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext.3)
78+
%vecext.4 = extractelement <16 x i32> %ptr.val, i32 4
79+
%call1.4 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext.4)
80+
%vecext.5 = extractelement <16 x i32> %ptr.val, i32 5
81+
%call1.5 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext.5)
82+
%vecext.6 = extractelement <16 x i32> %ptr.val, i32 6
83+
%call1.6 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 signext %vecext.6)
84+
%vecext2 = extractelement <16 x i32> %ptr.val, i32 7
85+
%call3 = tail call signext i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 signext %vecext2)
86+
ret void
87+
}
88+
89+
declare noundef signext i32 @printf(i8* nocapture noundef readonly, ...) nounwind
90+
91+
define dso_local void @test1(<4 x i32> %a, <4 x i32> %b) nounwind {
92+
; CHECK-LABEL: @test1(
93+
; CHECK-NEXT: entry:
94+
; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <4 x i32> [[A:%.*]], <4 x i32> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
95+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[B:%.*]], <4 x i32> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
96+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <16 x i32> [[TMP0]], <16 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
97+
; CHECK-NEXT: [[VECINIT22:%.*]] = shufflevector <16 x i32> [[TMP2]], <16 x i32> [[TMP1]], <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 16, i32 17, i32 18, i32 19, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
98+
; CHECK-NEXT: tail call fastcc void @printWideVec(<16 x i32> [[VECINIT22]])
99+
; CHECK-NEXT: ret void
100+
;
101+
entry:
102+
%0 = shufflevector <4 x i32> %a, <4 x i32> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
103+
%1 = shufflevector <4 x i32> %b, <4 x i32> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
104+
%2 = shufflevector <16 x i32> %0, <16 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
105+
%vecinit22 = shufflevector <16 x i32> %2, <16 x i32> %1, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 16, i32 17, i32 18, i32 19, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
106+
tail call fastcc void @printWideVec(<16 x i32> %vecinit22)
107+
ret void
108+
}

0 commit comments

Comments
 (0)