llvm.org GIT mirror llvm / 22b0358
[RS4GC] Handle ShuffleVector instruction in findBasePointer Summary: This patch modifies the findBasePointer to handle the shufflevector instruction. Tests run: RS4GC tests, local downstream tests. Reviewers: reames, sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25197 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283219 91177308-0d34-0410-b5e6-96231b3b80d8 Anna Thomas 2 years ago
2 changed file(s) with 111 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
675675 #ifndef NDEBUG
676676 auto isExpectedBDVType = [](Value *BDV) {
677677 return isa(BDV) || isa(BDV) ||
678 isa(BDV) || isa(BDV);
678 isa(BDV) || isa(BDV) ||
679 isa(BDV);
679680 };
680681 #endif
681682
718719 } else if (auto *IE = dyn_cast(Current)) {
719720 visitIncomingValue(IE->getOperand(0)); // vector operand
720721 visitIncomingValue(IE->getOperand(1)); // scalar operand
721 } else {
722 // There is one known class of instructions we know we don't handle.
723 assert(isa(Current));
722 } else if (auto *SV = dyn_cast(Current)) {
723 visitIncomingValue(SV->getOperand(0));
724 visitIncomingValue(SV->getOperand(1));
725 }
726 else {
724727 llvm_unreachable("Unimplemented instruction case");
725728 }
726729 }
777780 // useful in that it drives us to conflict if our input is.
778781 NewState =
779782 meetBDVState(NewState, getStateForInput(EE->getVectorOperand()));
780 } else {
783 } else if (auto *IE = dyn_cast(BDV)){
781784 // Given there's a inherent type mismatch between the operands, will
782785 // *always* produce Conflict.
783 auto *IE = cast(BDV);
784786 NewState = meetBDVState(NewState, getStateForInput(IE->getOperand(0)));
785787 NewState = meetBDVState(NewState, getStateForInput(IE->getOperand(1)));
788 } else {
789 // The only instance this does not return a Conflict is when both the
790 // vector operands are the same vector.
791 auto *SV = cast(BDV);
792 NewState = meetBDVState(NewState, getStateForInput(SV->getOperand(0)));
793 NewState = meetBDVState(NewState, getStateForInput(SV->getOperand(1)));
786794 }
787795
788796 BDVState OldState = States[BDV];
854862 std::string Name = suffixed_name_or(I, ".base", "base_ee");
855863 return ExtractElementInst::Create(Undef, EE->getIndexOperand(), Name,
856864 EE);
857 } else {
858 auto *IE = cast(I);
865 } else if (auto *IE = dyn_cast(I)) {
859866 UndefValue *VecUndef = UndefValue::get(IE->getOperand(0)->getType());
860867 UndefValue *ScalarUndef = UndefValue::get(IE->getOperand(1)->getType());
861868 std::string Name = suffixed_name_or(I, ".base", "base_ie");
862869 return InsertElementInst::Create(VecUndef, ScalarUndef,
863870 IE->getOperand(2), Name, IE);
871 } else {
872 auto *SV = cast(I);
873 UndefValue *VecUndef = UndefValue::get(SV->getOperand(0)->getType());
874 std::string Name = suffixed_name_or(I, ".base", "base_sv");
875 return new ShuffleVectorInst(VecUndef, VecUndef, SV->getOperand(2),
876 Name, SV);
864877 }
865878 };
866879 Instruction *BaseInst = MakeBaseInstPlaceholder(I);
962975 // Find the instruction which produces the base for each input. We may
963976 // need to insert a bitcast.
964977 BaseEE->setOperand(0, getBaseForInput(InVal, BaseEE));
965 } else {
966 auto *BaseIE = cast(State.getBaseValue());
978 } else if (auto *BaseIE = dyn_cast(State.getBaseValue())){
967979 auto *BdvIE = cast(BDV);
968980 auto UpdateOperand = [&](int OperandIdx) {
969981 Value *InVal = BdvIE->getOperand(OperandIdx);
972984 };
973985 UpdateOperand(0); // vector operand
974986 UpdateOperand(1); // scalar operand
987 } else {
988 auto *BaseSV = cast(State.getBaseValue());
989 auto *BdvSV = cast(BDV);
990 auto UpdateOperand = [&](int OperandIdx) {
991 Value *InVal = BdvSV->getOperand(OperandIdx);
992 Value *Base = getBaseForInput(InVal, BaseSV);
993 BaseSV->setOperand(OperandIdx, Base);
994 };
995 UpdateOperand(0); // vector operand
996 UpdateOperand(1); // vector operand
975997 }
976998 }
977999
164164 ret i64 addrspace(1)* %objb
165165 }
166166
167 ; identify base for shufflevector
168 define void @test8(i64 addrspace(1)* %obj, i64 %idx) gc "statepoint-example" {
169 ; CHECK-LABEL: @test8
170 ; CHECK: %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
171 ; CHECK: %gep2 = getelementptr i64, i64 addrspace(1)* %obj, i64 2
172 ; CHECK: %vec1.base = insertelement <4 x i64 addrspace(1)*> zeroinitializer, i64 addrspace(1)* %obj, i32 0, !is_base_value !0
173 ; CHECK: %vec1 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
174 ; CHECK: %vec2.base = insertelement <4 x i64 addrspace(1)*> zeroinitializer, i64 addrspace(1)* %obj, i32 2, !is_base_value !0
175 ; CHECK: %vec2 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep2, i32 2
176 ; CHECK: %vec.base = shufflevector <4 x i64 addrspace(1)*> %vec1.base, <4 x i64 addrspace(1)*> %vec2.base, <2 x i32> , !is_base_value !0
177 ; CHECK: %vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec2, <2 x i32>
178 ; CHECK: %bdv.base = extractelement <2 x i64 addrspace(1)*> %vec.base, i64 %idx, !is_base_value !0
179 ; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
180 ; CHECK: gc.statepoint
181 ; CHECK: gc.relocate
182 ; CHECK-DAG: (%bdv.base, %bdv)
183 entry:
184 %gep = getelementptr i64, i64 addrspace(1)* %obj, i64 1
185 %gep2 = getelementptr i64, i64 addrspace(1)* %obj, i64 2
186 %vec1 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep, i32 0
187 %vec2 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %gep2, i32 2
188 %vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec2, <2 x i32>
189 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
190 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
191 call void @use(i64 addrspace(1)* %bdv)
192 ret void
193 }
194
195 ; Since the same 'base' vector is used in the shuffle operands, we do not need
196 ; create a shufflevector base.
197 define void @test9(<4 x i64 addrspace(1)*> %vec1, i64 %idx) gc "statepoint-example" {
198 ; CHECK-LABEL: @test9
199 ; CHECK: %vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec1, <2 x i32>
200 ; CHECK: %base_ee = extractelement <4 x i64 addrspace(1)*> %vec1, i64 %idx, !is_base_value !0
201 ; CHECK: %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
202 ; CHECK: gc.statepoint
203 ; CHECK: gc.relocate
204 ; CHECK-DAG: (%base_ee, %bdv)
205 entry:
206 ; shrinking vec1 into vec
207 %vec = shufflevector <4 x i64 addrspace(1)*> %vec1, <4 x i64 addrspace(1)*> %vec1, <2 x i32>
208 %bdv = extractelement <2 x i64 addrspace(1)*> %vec, i64 %idx
209 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
210 call void @use(i64 addrspace(1)* %bdv)
211 ret void
212 }
213
214 ; vector operand of shufflevector is a phi
215 define i64 addrspace(1)* @test10(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
216 ; CHECK-LABEL: @test10
217 entry:
218 %vec1 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj, i32 0
219 br i1 %cnd, label %here, label %merge
220
221 here:
222 %vec2 = insertelement <4 x i64 addrspace(1)*> undef, i64 addrspace(1)* %obj2, i32 2
223 br label %merge
224
225 merge: ; preds = %merge, %entry, %here
226 ; CHECK-LABEL: merge:
227 ; CHECK: %vec.base = phi <4 x i64 addrspace(1)*> [ %vec1.base, %entry ], [ %vec2.base, %here ], [ %vec3.base, %merge ], !is_base_value !0
228 ; CHECK: vec
229 ; CHECK: vec3.base = shufflevector <4 x i64 addrspace(1)*> %vec.base, <4 x i64 addrspace(1)*> %vec.base
230 ; CHECK: vec3
231 ; CHECK: bdv.base
232 ; CHECK: bdv
233 %vec = phi <4 x i64 addrspace(1)*> [ %vec1, %entry ], [ %vec2, %here], [ %vec3, %merge]
234 %vec3 = shufflevector <4 x i64 addrspace(1)*> %vec, <4 x i64 addrspace(1)*> %vec, <4 x i32>
235 %bdv = extractelement <4 x i64 addrspace(1)*> %vec3, i32 0
236 br i1 %cnd, label %merge, label %next
237
238 next:
239 ; CHECK-LABEL: next:
240 ; CHECK: gc.statepoint
241 ; CHECK: gc.relocate
242 ; CHECK-DAG: (%bdv.base, %bdv)
243 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
244 ret i64 addrspace(1)* %bdv
245 }
167246 declare void @do_safepoint()