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