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