1; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs < %s | FileCheck %s
2; RUN: llc -mtriple=arm64-none-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s
3
4; LLVM should be able to cope with multiple uses of the same flag-setting
5; instruction at different points of a routine. Either by rematerializing the
6; compare or by saving and restoring the flag register.
7
8declare void @bar()
9
10@var = global i32 0
11
12define i32 @test_multiflag(i32 %n, i32 %m, i32 %o) {
13; CHECK-LABEL: test_multiflag:
14
15  %test = icmp ne i32 %n, %m
16; CHECK: cmp [[LHS:w[0-9]+]], [[RHS:w[0-9]+]]
17
18  %val = zext i1 %test to i32
19; CHECK: csinc {{[xw][0-9]+}}, {{xzr|wzr}}, {{xzr|wzr}}, eq
20
21  store i32 %val, i32* @var
22
23  call void @bar()
24; CHECK: bl bar
25
26  ; Currently, the comparison is emitted again. An MSR/MRS pair would also be
27  ; acceptable, but assuming the call preserves NZCV is not.
28  br i1 %test, label %iftrue, label %iffalse
29; CHECK: cmp [[LHS]], [[RHS]]
30; CHECK: b.eq
31
32iftrue:
33  ret i32 42
34iffalse:
35  ret i32 0
36}
37