llvm.org GIT mirror llvm / dd70def
[CodeGenPrepare] Don't create dead instructions in addrmode sinking When we fail to sink an instruction, we must make sure not to modify the function; otherwise, we end up in an infinite loop because CodeGenPrepare iterates until it doesn't make any changes. Fixes https://bugs.llvm.org/show_bug.cgi?id=33608 . git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307866 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Friedman 3 years ago
2 changed file(s) with 42 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
43924392 AddrMode.Scale = 0;
43934393 }
43944394
4395 // It is only safe to sign extend the BaseReg if we know that the math
4396 // required to create it did not overflow before we extend it. Since
4397 // the original IR value was tossed in favor of a constant back when
4398 // the AddrMode was created we need to bail out gracefully if widths
4399 // do not match instead of extending it.
4400 //
4401 // (See below for code to add the scale.)
4402 if (AddrMode.Scale) {
4403 Type *ScaledRegTy = AddrMode.ScaledReg->getType();
4404 if (cast(IntPtrTy)->getBitWidth() >
4405 cast(ScaledRegTy)->getBitWidth())
4406 return false;
4407 }
4408
43954409 if (AddrMode.BaseGV) {
43964410 if (ResultPtr)
43974411 return false;
44424456 Value *V = AddrMode.ScaledReg;
44434457 if (V->getType() == IntPtrTy) {
44444458 // done.
4445 } else if (cast(IntPtrTy)->getBitWidth() <
4446 cast(V->getType())->getBitWidth()) {
4459 } else {
4460 assert(cast(IntPtrTy)->getBitWidth() <
4461 cast(V->getType())->getBitWidth() &&
4462 "We can't transform if ScaledReg is too narrow");
44474463 V = Builder.CreateTrunc(V, IntPtrTy, "sunkaddr");
4448 } else {
4449 // It is only safe to sign extend the BaseReg if we know that the math
4450 // required to create it did not overflow before we extend it. Since
4451 // the original IR value was tossed in favor of a constant back when
4452 // the AddrMode was created we need to bail out gracefully if widths
4453 // do not match instead of extending it.
4454 Instruction *I = dyn_cast_or_null(ResultIndex);
4455 if (I && (ResultIndex != AddrMode.BaseReg))
4456 I->eraseFromParent();
4457 return false;
44584464 }
44594465
44604466 if (AddrMode.Scale != 1)
22 target datalayout =
33 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
44 target triple = "x86_64-unknown-linux-gnu"
5
6 @x = external global [1 x [2 x <4 x float>]]
57
68 ; Can we sink single addressing mode computation to use?
79 define void @test1(i1 %cond, i64* %base) {
193195
194196
195197 declare void @slowpath(i32, i32*)
198
199 ; Make sure we don't end up in an infinite loop after we fail to sink.
200 ; CHECK-LABEL: define void @test8
201 ; CHECK: %ptr = getelementptr i8, i8* %aFOO_load_ptr2int_2void, i32 undef
202 define void @test8() {
203 allocas:
204 %aFOO_load = load float*, float** undef
205 %aFOO_load_ptr2int = ptrtoint float* %aFOO_load to i64
206 %aFOO_load_ptr2int_broadcast_init = insertelement <4 x i64> undef, i64 %aFOO_load_ptr2int, i32 0
207 %aFOO_load_ptr2int_2void = inttoptr i64 %aFOO_load_ptr2int to i8*
208 %ptr = getelementptr i8, i8* %aFOO_load_ptr2int_2void, i32 undef
209 br label %load.i145
210
211 load.i145:
212 %ptr.i143 = bitcast i8* %ptr to <4 x float>*
213 %valall.i144 = load <4 x float>, <4 x float>* %ptr.i143, align 4
214 %x_offset = getelementptr [1 x [2 x <4 x float>]], [1 x [2 x <4 x float>]]* @x, i32 0, i64 0
215 br label %pl_loop.i.i122
216
217 pl_loop.i.i122:
218 br label %pl_loop.i.i122
219 }