1 |
commit: 3b7815004b8f2952c642c81bbfb37cd7945e6cc3 |
2 |
Author: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed May 25 20:08:49 2022 +0000 |
4 |
Commit: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed May 25 21:09:32 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3b781500 |
7 |
|
8 |
dev-lang/rust: add llvm patches to 1.61.0 to fix SIGFPE |
9 |
|
10 |
Bug: https://bugs.gentoo.org/847421 |
11 |
Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org> |
12 |
|
13 |
.../rust/files/1.61.0-llvm_addrspacecast.patch | 52 +++++++++++++++++ |
14 |
.../files/1.61.0-llvm_selectInterleaveCount.patch | 66 ++++++++++++++++++++++ |
15 |
.../{rust-1.61.0.ebuild => rust-1.61.0-r1.ebuild} | 2 + |
16 |
3 files changed, 120 insertions(+) |
17 |
|
18 |
diff --git a/dev-lang/rust/files/1.61.0-llvm_addrspacecast.patch b/dev-lang/rust/files/1.61.0-llvm_addrspacecast.patch |
19 |
new file mode 100644 |
20 |
index 000000000000..9f2ca6ff667b |
21 |
--- /dev/null |
22 |
+++ b/dev-lang/rust/files/1.61.0-llvm_addrspacecast.patch |
23 |
@@ -0,0 +1,52 @@ |
24 |
+From 67a290460c374d5e0d18a06c798896cac0b19e59 Mon Sep 17 00:00:00 2001 |
25 |
+From: Fraser Cormack <fraser@××××××××.com> |
26 |
+Date: Wed, 16 Mar 2022 10:14:07 +0000 |
27 |
+Subject: [PATCH] [VectorCombine] Insert addrspacecast when crossing address |
28 |
+ space boundaries |
29 |
+ |
30 |
+We can not bitcast pointers across different address spaces. This was |
31 |
+previously fixed in D89577 but then in D93229 an enhancement was added |
32 |
+which peeks further through the ponter operand, opening up the |
33 |
+possibility that address-space violations could be introduced. |
34 |
+ |
35 |
+Instead of bailing as the previous fix did, simply insert an |
36 |
+addrspacecast cast instruction. |
37 |
+ |
38 |
+Reviewed By: lebedev.ri |
39 |
+ |
40 |
+Differential Revision: https://reviews.llvm.org/D121787 |
41 |
+ |
42 |
+(cherry picked from commit 2e44b7872bc638ed884ae4aa86e38b3b47e0b65a) |
43 |
+--- |
44 |
+ llvm/lib/Transforms/Vectorize/VectorCombine.cpp | 8 ++------ |
45 |
+ .../AMDGPU/as-transition-inseltpoison.ll | 4 +--- |
46 |
+ .../VectorCombine/AMDGPU/as-transition.ll | 4 +--- |
47 |
+ .../VectorCombine/X86/load-inseltpoison.ll | 17 +++++++++++++++++ |
48 |
+ 4 files changed, 21 insertions(+), 12 deletions(-) |
49 |
+ |
50 |
+diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp |
51 |
+index 620d388199e0..258f6c67e54d 100644 |
52 |
+--- a/src/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp |
53 |
++++ b/src/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp |
54 |
+@@ -152,12 +152,7 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) { |
55 |
+ Value *SrcPtr = Load->getPointerOperand()->stripPointerCasts(); |
56 |
+ assert(isa<PointerType>(SrcPtr->getType()) && "Expected a pointer type"); |
57 |
+ |
58 |
+- // If original AS != Load's AS, we can't bitcast the original pointer and have |
59 |
+- // to use Load's operand instead. Ideally we would want to strip pointer casts |
60 |
+- // without changing AS, but there's no API to do that ATM. |
61 |
+ unsigned AS = Load->getPointerAddressSpace(); |
62 |
+- if (AS != SrcPtr->getType()->getPointerAddressSpace()) |
63 |
+- SrcPtr = Load->getPointerOperand(); |
64 |
+ |
65 |
+ // We are potentially transforming byte-sized (8-bit) memory accesses, so make |
66 |
+ // sure we have all of our type-based constraints in place for this target. |
67 |
+@@ -245,7 +240,8 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) { |
68 |
+ // It is safe and potentially profitable to load a vector directly: |
69 |
+ // inselt undef, load Scalar, 0 --> load VecPtr |
70 |
+ IRBuilder<> Builder(Load); |
71 |
+- Value *CastedPtr = Builder.CreateBitCast(SrcPtr, MinVecTy->getPointerTo(AS)); |
72 |
++ Value *CastedPtr = Builder.CreatePointerBitCastOrAddrSpaceCast( |
73 |
++ SrcPtr, MinVecTy->getPointerTo(AS)); |
74 |
+ Value *VecLd = Builder.CreateAlignedLoad(MinVecTy, CastedPtr, Alignment); |
75 |
+ VecLd = Builder.CreateShuffleVector(VecLd, Mask); |
76 |
|
77 |
diff --git a/dev-lang/rust/files/1.61.0-llvm_selectInterleaveCount.patch b/dev-lang/rust/files/1.61.0-llvm_selectInterleaveCount.patch |
78 |
new file mode 100644 |
79 |
index 000000000000..71a4e8df75d8 |
80 |
--- /dev/null |
81 |
+++ b/dev-lang/rust/files/1.61.0-llvm_selectInterleaveCount.patch |
82 |
@@ -0,0 +1,66 @@ |
83 |
+From fe8a27acd716a42667f5a572f52f2b04636010ff Mon Sep 17 00:00:00 2001 |
84 |
+From: Florian Hahn <flo@×××××.com> |
85 |
+Date: Tue, 29 Mar 2022 22:52:42 +0100 |
86 |
+Subject: [PATCH] [LV] Handle zero cost loops in selectInterleaveCount. |
87 |
+ |
88 |
+In some case, like in the added test case, we can reach |
89 |
+selectInterleaveCount with loops that actually have a cost of 0. |
90 |
+ |
91 |
+Unfortunately a loop cost of 0 is also used to communicate that the cost |
92 |
+has not been computed yet. To resolve the crash, bail out if the cost |
93 |
+remains zero after computing it. |
94 |
+ |
95 |
+This seems like the best option, as there are multiple code paths that |
96 |
+return a cost of 0 to force a computation in selectInterleaveCount. |
97 |
+Computing the cost at multiple places up front there would unnecessarily |
98 |
+complicate the logic. |
99 |
+ |
100 |
+Fixes #54413. |
101 |
+ |
102 |
+(cherry picked from commit ecb4171dcbf1b433c9963fd605a74898303e850d) |
103 |
+--- |
104 |
+ .../Transforms/Vectorize/LoopVectorize.cpp | 22 ++++---- |
105 |
+ ...ct-interleave-count-loop-with-cost-zero.ll | 50 +++++++++++++++++++ |
106 |
+ 2 files changed, 62 insertions(+), 10 deletions(-) |
107 |
+ create mode 100644 llvm/test/Transforms/LoopVectorize/X86/pr54413-select-interleave-count-loop-with-cost-zero.ll |
108 |
+ |
109 |
+diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp |
110 |
+index 21c16f07e237..e1cc7946073e 100644 |
111 |
+--- a/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp |
112 |
++++ b/src/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp |
113 |
+@@ -6035,6 +6035,18 @@ unsigned LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF, |
114 |
+ !(InterleaveSmallLoopScalarReduction && HasReductions && VF.isScalar())) |
115 |
+ return 1; |
116 |
+ |
117 |
++ // If we did not calculate the cost for VF (because the user selected the VF) |
118 |
++ // then we calculate the cost of VF here. |
119 |
++ if (LoopCost == 0) { |
120 |
++ InstructionCost C = expectedCost(VF).first; |
121 |
++ assert(C.isValid() && "Expected to have chosen a VF with valid cost"); |
122 |
++ LoopCost = *C.getValue(); |
123 |
++ |
124 |
++ // Loop body is free and there is no need for interleaving. |
125 |
++ if (LoopCost == 0) |
126 |
++ return 1; |
127 |
++ } |
128 |
++ |
129 |
+ RegisterUsage R = calculateRegisterUsage({VF})[0]; |
130 |
+ // We divide by these constants so assume that we have at least one |
131 |
+ // instruction that uses at least one register. |
132 |
+@@ -6126,16 +6138,6 @@ unsigned LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF, |
133 |
+ |
134 |
+ assert(IC > 0 && "Interleave count must be greater than 0."); |
135 |
+ |
136 |
+- // If we did not calculate the cost for VF (because the user selected the VF) |
137 |
+- // then we calculate the cost of VF here. |
138 |
+- if (LoopCost == 0) { |
139 |
+- InstructionCost C = expectedCost(VF).first; |
140 |
+- assert(C.isValid() && "Expected to have chosen a VF with valid cost"); |
141 |
+- LoopCost = *C.getValue(); |
142 |
+- } |
143 |
+- |
144 |
+- assert(LoopCost && "Non-zero loop cost expected"); |
145 |
+- |
146 |
+ // Interleave if we vectorized this loop and there is a reduction that could |
147 |
+ // benefit from interleaving. |
148 |
+ if (VF.isVector() && HasReductions) { |
149 |
|
150 |
diff --git a/dev-lang/rust/rust-1.61.0.ebuild b/dev-lang/rust/rust-1.61.0-r1.ebuild |
151 |
similarity index 99% |
152 |
rename from dev-lang/rust/rust-1.61.0.ebuild |
153 |
rename to dev-lang/rust/rust-1.61.0-r1.ebuild |
154 |
index e503b90edf91..f8852b27e97e 100644 |
155 |
--- a/dev-lang/rust/rust-1.61.0.ebuild |
156 |
+++ b/dev-lang/rust/rust-1.61.0-r1.ebuild |
157 |
@@ -156,6 +156,8 @@ VERIFY_SIG_OPENPGP_KEY_PATH=${BROOT}/usr/share/openpgp-keys/rust.asc |
158 |
PATCHES=( |
159 |
"${FILESDIR}"/1.55.0-ignore-broken-and-non-applicable-tests.patch |
160 |
"${FILESDIR}"/1.61.0-gentoo-musl-target-specs.patch |
161 |
+ "${FILESDIR}"/1.61.0-llvm_selectInterleaveCount.patch |
162 |
+ "${FILESDIR}"/1.61.0-llvm_addrspacecast.patch |
163 |
) |
164 |
|
165 |
S="${WORKDIR}/${MY_P}-src" |