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 --aarch64prelegalizercombinerhelper-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: successors: %bb.1(0x40000000), %bb.2(0x40000000)
42 ; CHECK: liveins: $w0, $w1
43 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
44 ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
45 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
46 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
47 ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(sgt), [[COPY]](s32), [[C]]
48 ; CHECK: [[C2:%[0-9]+]]:_(s1) = G_CONSTANT i1 true
49 ; CHECK: [[XOR:%[0-9]+]]:_(s1) = G_XOR [[ICMP]], [[C2]]
50 ; CHECK: G_BRCOND [[XOR]](s1), %bb.2
52 ; CHECK: bb.1.if.then:
53 ; CHECK: successors: %bb.3(0x80000000)
54 ; CHECK: [[ADD:%[0-9]+]]:_(s32) = nsw G_ADD [[COPY1]], [[COPY]]
55 ; CHECK: [[ADD1:%[0-9]+]]:_(s32) = nsw G_ADD [[ADD]], [[COPY1]]
58 ; CHECK: successors: %bb.3(0x80000000)
59 ; CHECK: [[MUL:%[0-9]+]]:_(s32) = nsw G_MUL [[COPY1]], [[COPY1]]
60 ; CHECK: [[ADD2:%[0-9]+]]:_(s32) = nuw nsw G_ADD [[MUL]], [[C1]]
62 ; CHECK: [[PHI:%[0-9]+]]:_(s32) = G_PHI [[ADD1]](s32), %bb.1, [[ADD2]](s32), %bb.2
63 ; CHECK: $w0 = COPY [[PHI]](s32)
64 ; CHECK: RET_ReallyLR implicit $w0
70 %2:_(s32) = G_CONSTANT i32 0
71 %5:_(s32) = G_CONSTANT i32 2
72 %3:_(s1) = G_ICMP intpred(sgt), %0(s32), %2
73 G_BRCOND %3(s1), %bb.2
77 %7:_(s32) = nsw G_ADD %1, %0
78 %8:_(s32) = nsw G_ADD %7, %1
82 %4:_(s32) = nsw G_MUL %1, %1
83 %6:_(s32) = nuw nsw G_ADD %4, %5
86 %10:_(s32) = G_PHI %8(s32), %bb.2, %6(s32), %bb.3
88 RET_ReallyLR implicit $w0
92 name: dont_combine_same_block
93 tracksRegLiveness: true
95 ; CHECK-LABEL: name: dont_combine_same_block
97 ; CHECK: successors: %bb.1(0x80000000)
98 ; CHECK: liveins: $w0, $w1
99 ; CHECK: %cond:_(s1) = G_IMPLICIT_DEF
100 ; CHECK: G_BRCOND %cond(s1), %bb.1
103 ; CHECK: RET_ReallyLR
106 %cond:_(s1) = G_IMPLICIT_DEF
108 ; The G_BRCOND and G_BR have the same target here. Don't change anything.
109 G_BRCOND %cond(s1), %bb.1