1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -debugify-and-strip-all-safe -O0 -run-pass=aarch64-prelegalizer-combiner --aarch64prelegalizercombiner-only-enable-rule="opt_brcond_by_inverting_cond" -global-isel -verify-machineinstrs %s -o - | FileCheck %s
4 # Need asserts for the only-enable-rule to work.
9 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
10 target triple = "arm64-apple-ios5.0.0"
12 define i32 @foo(i32 %a, i32 %b) {
14 %cmp = icmp sgt i32 %a, 0
15 br i1 %cmp, label %if.then, label %if.end
18 %add = add nsw i32 %b, %a
19 %add1 = add nsw i32 %a, %b
23 %mul = mul nsw i32 %b, %b
24 %add2 = add nuw nsw i32 %mul, 2
28 %retval.0 = phi i32 [ %add1, %if.then ], [ %add2, %if.end ]
32 define void @dont_combine_same_block() { ret void }
37 tracksRegLiveness: true
39 ; CHECK-LABEL: name: foo
41 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
42 ; CHECK-NEXT: liveins: $w0, $w1
44 ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
45 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
46 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
47 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
48 ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(sgt), [[COPY]](s32), [[C]]
49 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s1) = G_CONSTANT i1 true
50 ; CHECK-NEXT: [[XOR:%[0-9]+]]:_(s1) = G_XOR [[ICMP]], [[C2]]
51 ; CHECK-NEXT: G_BRCOND [[XOR]](s1), %bb.2
52 ; CHECK-NEXT: G_BR %bb.1
54 ; CHECK-NEXT: bb.1.if.then:
55 ; CHECK-NEXT: successors: %bb.3(0x80000000)
57 ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s32) = nsw G_ADD [[COPY1]], [[COPY]]
58 ; CHECK-NEXT: [[ADD1:%[0-9]+]]:_(s32) = nsw G_ADD [[ADD]], [[COPY1]]
59 ; CHECK-NEXT: G_BR %bb.3
61 ; CHECK-NEXT: bb.2.if.end:
62 ; CHECK-NEXT: successors: %bb.3(0x80000000)
64 ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s32) = nsw G_MUL [[COPY1]], [[COPY1]]
65 ; CHECK-NEXT: [[ADD2:%[0-9]+]]:_(s32) = nuw nsw G_ADD [[MUL]], [[C1]]
67 ; CHECK-NEXT: bb.3.return:
68 ; CHECK-NEXT: [[PHI:%[0-9]+]]:_(s32) = G_PHI [[ADD1]](s32), %bb.1, [[ADD2]](s32), %bb.2
69 ; CHECK-NEXT: $w0 = COPY [[PHI]](s32)
70 ; CHECK-NEXT: RET_ReallyLR implicit $w0
76 %2:_(s32) = G_CONSTANT i32 0
77 %5:_(s32) = G_CONSTANT i32 2
78 %3:_(s1) = G_ICMP intpred(sgt), %0(s32), %2
79 G_BRCOND %3(s1), %bb.2
83 %7:_(s32) = nsw G_ADD %1, %0
84 %8:_(s32) = nsw G_ADD %7, %1
88 %4:_(s32) = nsw G_MUL %1, %1
89 %6:_(s32) = nuw nsw G_ADD %4, %5
92 %10:_(s32) = G_PHI %8(s32), %bb.2, %6(s32), %bb.3
94 RET_ReallyLR implicit $w0
98 name: dont_combine_same_block
99 tracksRegLiveness: true
101 ; CHECK-LABEL: name: dont_combine_same_block
103 ; CHECK-NEXT: successors: %bb.1(0x80000000)
104 ; CHECK-NEXT: liveins: $w0, $w1
106 ; CHECK-NEXT: %cond:_(s1) = G_IMPLICIT_DEF
107 ; CHECK-NEXT: G_BRCOND %cond(s1), %bb.1
108 ; CHECK-NEXT: G_BR %bb.1
111 ; CHECK-NEXT: RET_ReallyLR
114 %cond:_(s1) = G_IMPLICIT_DEF
116 G_BRCOND %cond(s1), %bb.1