1; RUN: opt < %s -loop-reduce -S | FileCheck %s
2
3target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4target triple = "x86_64-apple-macosx10.9.0"
5
6; LSR shouldn't normalize IV if it can't be denormalized to the original
7; expression.  In this testcase, the normalized expression was denormalized to
8; an expression different from the original, and we were losing sign extension.
9
10; CHECK:    [[TMP:%[a-z]+]] = trunc i32 {{.*}} to i8
11; CHECK:     {{%[a-z0-9]+}} = sext i8 [[TMP]] to i32
12
13@j = common global i32 0, align 4
14@c = common global i32 0, align 4
15@g = common global i32 0, align 4
16@h = common global i8 0, align 1
17@d = common global i32 0, align 4
18@i = common global i32 0, align 4
19@e = common global i32 0, align 4
20@.str = private unnamed_addr constant [4 x i8] c"%x\0A\00", align 1
21@a = common global i32 0, align 4
22@b = common global i16 0, align 2
23
24; Function Attrs: nounwind optsize ssp uwtable
25define i32 @main() #0 {
26entry:
27  store i8 0, i8* @h, align 1
28  %0 = load i32, i32* @j, align 4
29  %tobool.i = icmp eq i32 %0, 0
30  %1 = load i32, i32* @d, align 4
31  %cmp3 = icmp sgt i32 %1, -1
32  %.lobit = lshr i32 %1, 31
33  %.lobit.not = xor i32 %.lobit, 1
34  br label %for.body
35
36for.body:                                         ; preds = %entry, %fn3.exit
37  %inc9 = phi i8 [ 0, %entry ], [ %inc, %fn3.exit ]
38  %conv = sext i8 %inc9 to i32
39  br i1 %tobool.i, label %fn3.exit, label %land.rhs.i
40
41land.rhs.i:                                       ; preds = %for.body
42  store i32 0, i32* @c, align 4
43  br label %fn3.exit
44
45fn3.exit:                                         ; preds = %for.body, %land.rhs.i
46  %inc = add i8 %inc9, 1
47  %cmp = icmp sgt i8 %inc, -1
48  br i1 %cmp, label %for.body, label %for.end
49
50for.end:                                          ; preds = %fn3.exit
51  %.lobit.not. = select i1 %cmp3, i32 %.lobit.not, i32 0
52  store i32 %conv, i32* @g, align 4
53  store i32 %.lobit.not., i32* @i, align 4
54  store i8 %inc, i8* @h, align 1
55  %conv7 = sext i8 %inc to i32
56  %add = add nsw i32 %conv7, %conv
57  store i32 %add, i32* @e, align 4
58  %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %add) #2
59  ret i32 0
60}
61
62; Function Attrs: nounwind optsize
63declare i32 @printf(i8* nocapture readonly, ...) #1
64
65attributes #0 = { nounwind optsize ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
66attributes #1 = { nounwind optsize "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
67attributes #2 = { nounwind optsize }
68