1; RUN: llc -o - %s | FileCheck %s
2; This tests for the problem originally reported in http://llvm.org/PR25951
3target triple = "i686-unknown-linux-gnu"
4
5@b = common global i8 0, align 1
6@c = common global i32 0, align 4
7@a = common global i8 0, align 1
8@d = common global i8 0, align 1
9@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
10
11; CHECK-LABEL: func:
12; This tests whether eax is properly saved/restored around the lahf/sahf
13; instruction sequences.
14define i32 @func() {
15entry:
16  %bval = load i8, i8* @b
17  %inc = add i8 %bval, 1
18  store i8 %inc, i8* @b
19  %cval = load i32, i32* @c
20  %inc1 = add nsw i32 %cval, 1
21  store i32 %inc1, i32* @c
22  %aval = load i8, i8* @a
23  %inc2 = add i8 %aval, 1
24  store i8 %inc2, i8* @a
25; Copy flags produced by the incb of %inc1 to a register, need to save+restore
26; eax around it. The flags will be reused by %tobool.
27; CHECK: pushl %eax
28; CHECK: seto %al
29; CHECK: lahf
30; CHECK: movl %eax, [[REG:%[a-z]+]]
31; CHECK: popl %eax
32  %cmp = icmp eq i8 %aval, %bval
33  %conv5 = zext i1 %cmp to i8
34  store i8 %conv5, i8* @d
35  %tobool = icmp eq i32 %inc1, 0
36; We restore flags with an 'addb, sahf' sequence, need to save+restore eax
37; around it.
38; CHECK: pushl %eax
39; CHECK: movl [[REG]], %eax
40; CHECK: addb $127, %al
41; CHECK: sahf
42; CHECK: popl %eax
43  br i1 %tobool, label %if.end, label %if.then
44
45if.then:
46  %conv6 = sext i8 %inc to i32
47  %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %conv6)
48  br label %if.end
49
50if.end:
51  ret i32 0
52}
53
54declare i32 @printf(i8* nocapture readonly, ...)
55