1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py 2; RUN: opt < %s -S -analyze -enable-new-pm=0 -scalar-evolution | FileCheck %s 3; RUN: opt < %s -S -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s 4 5; Reduced from test-suite/MultiSource/Benchmarks/MiBench/office-ispell/correct.c 6; getelementptr, obviously, takes pointer as it's base, and returns a pointer. 7; SCEV operands are sorted in hope that it increases folding potential, 8; and at the same time SCEVAddExpr's type is the type of the last(!) operand. 9; Which means, in some exceedingly rare cases, pointer operand may happen to 10; end up not being the last operand, and as a result SCEV for GEP will suddenly 11; have a non-pointer return type. We should ensure that does not happen. 12 13target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 14target triple = "x86_64-unknown-linux-gnu" 15 16@c = dso_local local_unnamed_addr global i32* null, align 8 17@a = dso_local local_unnamed_addr global i32 0, align 4 18@b = dso_local global [1 x i32] zeroinitializer, align 4 19 20define i32 @d(i32 %base) { 21; CHECK-LABEL: 'd' 22; CHECK-NEXT: Classifying expressions for: @d 23; CHECK-NEXT: %e = alloca [1 x [1 x i8]], align 1 24; CHECK-NEXT: --> %e U: full-set S: full-set 25; CHECK-NEXT: %0 = bitcast [1 x [1 x i8]]* %e to i8* 26; CHECK-NEXT: --> %e U: full-set S: full-set 27; CHECK-NEXT: %f.0 = phi i32 [ %base, %entry ], [ %inc, %for.cond ] 28; CHECK-NEXT: --> {%base,+,1}<nsw><%for.cond> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Computable } 29; CHECK-NEXT: %idxprom = sext i32 %f.0 to i64 30; CHECK-NEXT: --> {(sext i32 %base to i64),+,1}<nsw><%for.cond> U: [-2147483648,-9223372036854775808) S: [-2147483648,-9223372036854775808) Exits: <<Unknown>> LoopDispositions: { %for.cond: Computable } 31; CHECK-NEXT: %arrayidx = getelementptr inbounds [1 x [1 x i8]], [1 x [1 x i8]]* %e, i64 0, i64 %idxprom 32; CHECK-NEXT: --> {((sext i32 %base to i64) + %e),+,1}<nw><%for.cond> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Computable } 33; CHECK-NEXT: %1 = load i32*, i32** @c, align 8 34; CHECK-NEXT: --> %1 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 35; CHECK-NEXT: %sub.ptr.lhs.cast = ptrtoint i32* %1 to i64 36; CHECK-NEXT: --> (ptrtoint i32* %1 to i64) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 37; CHECK-NEXT: %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, ptrtoint ([1 x i32]* @b to i64) 38; CHECK-NEXT: --> ((-1 * (ptrtoint [1 x i32]* @b to i64)) + (ptrtoint i32* %1 to i64)) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 39; CHECK-NEXT: %sub.ptr.div = sdiv exact i64 %sub.ptr.sub, 4 40; CHECK-NEXT: --> %sub.ptr.div U: [-2305843009213693952,2305843009213693952) S: [-2305843009213693952,2305843009213693952) Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 41; CHECK-NEXT: %arrayidx1 = getelementptr inbounds [1 x i8], [1 x i8]* %arrayidx, i64 0, i64 %sub.ptr.div 42; CHECK-NEXT: --> ({((sext i32 %base to i64) + %e),+,1}<nw><%for.cond> + %sub.ptr.div) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 43; CHECK-NEXT: %2 = load i8, i8* %arrayidx1, align 1 44; CHECK-NEXT: --> %2 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 45; CHECK-NEXT: %conv = sext i8 %2 to i32 46; CHECK-NEXT: --> (sext i8 %2 to i32) U: [-128,128) S: [-128,128) Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant } 47; CHECK-NEXT: %inc = add nsw i32 %f.0, 1 48; CHECK-NEXT: --> {(1 + %base),+,1}<nw><%for.cond> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Computable } 49; CHECK-NEXT: Determining loop execution counts for: @d 50; CHECK-NEXT: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count. 51; CHECK-NEXT: Loop %for.cond: Unpredictable max backedge-taken count. 52; CHECK-NEXT: Loop %for.cond: Unpredictable predicated backedge-taken count. 53; 54entry: 55 %e = alloca [1 x [1 x i8]], align 1 56 %0 = bitcast [1 x [1 x i8]]* %e to i8* 57 call void @llvm.lifetime.start.p0i8(i64 1, i8* %0) #2 58 br label %for.cond 59 60for.cond: ; preds = %for.cond, %entry 61 %f.0 = phi i32 [ %base, %entry ], [ %inc, %for.cond ] 62 %idxprom = sext i32 %f.0 to i64 63 %arrayidx = getelementptr inbounds [1 x [1 x i8]], [1 x [1 x i8]]* %e, i64 0, i64 %idxprom 64 %1 = load i32*, i32** @c, align 8 65 %sub.ptr.lhs.cast = ptrtoint i32* %1 to i64 66 %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, ptrtoint ([1 x i32]* @b to i64) 67 %sub.ptr.div = sdiv exact i64 %sub.ptr.sub, 4 68 %arrayidx1 = getelementptr inbounds [1 x i8], [1 x i8]* %arrayidx, i64 0, i64 %sub.ptr.div 69 %2 = load i8, i8* %arrayidx1, align 1 70 %conv = sext i8 %2 to i32 71 store i32 %conv, i32* @a, align 4 72 %inc = add nsw i32 %f.0, 1 73 br label %for.cond 74} 75 76declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) 77