llvm.org GIT mirror llvm / 7d4d59c
[RS4GC] Avoid crashing on gep scalar_base, vector_idx This is an alternative to https://reviews.llvm.org/D57103. After discussion, we dedicided to check this in as a temporary workaround, and pursue a true fix under the original thread. The issue at hand is that the base rewriting algorithm doesn't consider the fact that GEPs can turn a scalar input into a vector of outputs. We had handling for scalar GEPs and fully vector GEPs (i.e. all vector operands), but not the scalar-base + vector-index forms. A true fix here requires treating GEP analogously to extractelement or shufflevector. This patch is merely a workaround. It simply hides the crash at the cost of some ugly code gen for this presumable very rare pattern. Differential Revision: https://reviews.llvm.org/D57138 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352059 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 7 months ago
3 changed file(s) with 55 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
26002600 }
26012601 }
26022602
2603 // Nasty workaround - The base computation code in the main algorithm doesn't
2604 // consider the fact that a GEP can be used to convert a scalar to a vector.
2605 // The right fix for this is to integrate GEPs into the base rewriting
2606 // algorithm properly, this is just a short term workaround to prevent
2607 // crashes by canonicalizing such GEPs into fully vector GEPs.
2608 for (Instruction &I : instructions(F)) {
2609 if (!isa(I))
2610 continue;
2611
2612 unsigned VF = 0;
2613 bool HasScalarOperand = false;
2614 for (unsigned i = 0; i < I.getNumOperands(); i++)
2615 if (I.getOperand(i)->getType()->isVectorTy())
2616 VF = I.getOperand(i)->getType()->getVectorNumElements();
2617 else
2618 HasScalarOperand = true;
2619
2620 if (HasScalarOperand && VF != 0) {
2621 IRBuilder<> B(&I);
2622 for (unsigned i = 0; i < I.getNumOperands(); i++)
2623 if (!I.getOperand(i)->getType()->isVectorTy()) {
2624 auto *Splat = B.CreateVectorSplat(VF, I.getOperand(i));
2625 I.setOperand(i, Splat);
2626 MadeChange = true;
2627 }
2628 }
2629 }
2630
26032631 MadeChange |= insertParsePoints(F, DT, TTI, ParsePointNeeded);
26042632 return MadeChange;
26052633 }
252252 ; CHECK: @llvm.experimental.gc.statepoint.p0f_isVoidf{{.*}}<4 x i64 addrspace(1)*> %vec1)
253253 ; CHECK: %vec1.relocated = call coldcc <4 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v4p1i8
254254 ; CHECK: %vec1.relocated.casted = bitcast <4 x i8 addrspace(1)*> %vec1.relocated to <4 x i64 addrspace(1)*>
255 ; CHECK: %vec2.remat = getelementptr i64, <4 x i64 addrspace(1)*> %vec1.relocated.casted, i32 1024
255 ; CHECK: %vec2.remat = getelementptr i64, <4 x i64 addrspace(1)*> %vec1.relocated.casted, <4 x i32>
256256 ; CHECK: call void @use_vec(<4 x i64 addrspace(1)*> %vec2.remat)
257257 entry:
258258 %vec2 = getelementptr i64, <4 x i64 addrspace(1)*> %vec1, i32 1024
0 ; RUN: opt < %s -rewrite-statepoints-for-gc -S | FileCheck %s
1 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -S | FileCheck %s
2
3 declare void @do_safepoint()
4 declare i8 addrspace(1)* @def_ptr()
5
6 define i32 addrspace(1)* @test1(i8 addrspace(1)* %base1, <2 x i64> %offsets) gc "statepoint-example" {
7 entry:
8 br i1 undef, label %first, label %second
9
10 first:
11 %base2 = call i8 addrspace(1)* @def_ptr() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
12 br label %second
13
14 second:
15 ; CHECK-LABEL: @test1(
16 ; CHECK: gc.statepoint
17 ; CHECK-DAG: (%ptr.base, %ptr)
18 ; CHECK-DAG: (%ptr.base, %ptr.base)
19 %phi = phi i8 addrspace(1)* [ %base1, %entry ], [ %base2, %first ]
20 %base.i32 = bitcast i8 addrspace(1)* %phi to i32 addrspace(1)*
21 %vec = getelementptr i32, i32 addrspace(1)* %base.i32, <2 x i64> %offsets
22 %ptr = extractelement <2 x i32 addrspace(1)*> %vec, i32 1
23 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
24 ret i32 addrspace(1)* %ptr
25 }