1; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s 2 3define i32 @test_return(i32* %p, i32 %oldval, i32 %newval) { 4; CHECK-LABEL: test_return: 5 6; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]: 7; CHECK: ldaxr [[LOADED:w[0-9]+]], [x0] 8; CHECK: cmp [[LOADED]], w1 9; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]] 10 11; CHECK: stlxr [[STATUS:w[0-9]+]], {{w[0-9]+}}, [x0] 12; CHECK: cbnz [[STATUS]], [[LOOP]] 13 14; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 15; CHECK: orr w0, wzr, #0x1 16; CHECK: ret 17 18; CHECK: [[FAILED]]: 19; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 20; CHECK: mov w0, wzr 21; CHECK: ret 22 23 %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst 24 %success = extractvalue { i32, i1 } %pair, 1 25 %conv = zext i1 %success to i32 26 ret i32 %conv 27} 28 29define i1 @test_return_bool(i8* %value, i8 %oldValue, i8 %newValue) { 30; CHECK-LABEL: test_return_bool: 31 32; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]: 33; CHECK: ldaxrb [[LOADED:w[0-9]+]], [x0] 34; CHECK: cmp [[LOADED]], w1, uxtb 35; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]] 36 37; CHECK: stlxrb [[STATUS:w[0-9]+]], {{w[0-9]+}}, [x0] 38; CHECK: cbnz [[STATUS]], [[LOOP]] 39 40; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 41 ; FIXME: DAG combine should be able to deal with this. 42; CHECK: orr [[TMP:w[0-9]+]], wzr, #0x1 43; CHECK: eor w0, [[TMP]], #0x1 44; CHECK: ret 45 46; CHECK: [[FAILED]]: 47; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 48; CHECK: eor w0, wzr, #0x1 49; CHECK: ret 50 51 %pair = cmpxchg i8* %value, i8 %oldValue, i8 %newValue acq_rel monotonic 52 %success = extractvalue { i8, i1 } %pair, 1 53 %failure = xor i1 %success, 1 54 ret i1 %failure 55} 56 57define void @test_conditional(i32* %p, i32 %oldval, i32 %newval) { 58; CHECK-LABEL: test_conditional: 59 60; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]: 61; CHECK: ldaxr [[LOADED:w[0-9]+]], [x0] 62; CHECK: cmp [[LOADED]], w1 63; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]] 64 65; CHECK: stlxr [[STATUS:w[0-9]+]], w2, [x0] 66; CHECK: cbnz [[STATUS]], [[LOOP]] 67 68; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 69; CHECK: b _bar 70 71; CHECK: [[FAILED]]: 72; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 73; CHECK: b _baz 74 75 %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst 76 %success = extractvalue { i32, i1 } %pair, 1 77 br i1 %success, label %true, label %false 78 79true: 80 tail call void @bar() #2 81 br label %end 82 83false: 84 tail call void @baz() #2 85 br label %end 86 87end: 88 ret void 89} 90 91declare void @bar() 92declare void @baz() 93 94define i1 @test_conditional2(i32 %a, i32 %b, i32* %c) { 95; CHECK-LABEL: test_conditional2: 96; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]: 97; CHECK: ldaxr [[LOADED:w[0-9]+]], [x19] 98; CHECK: cmp [[LOADED]], w21 99; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]] 100 101; CHECK: stlxr [[STATUS:w[0-9]+]], w20, [x19] 102; CHECK: cbnz [[STATUS]], [[LOOP]] 103; CHECK: orr [[STATUS]], wzr, #0x1 104; CHECK: b [[PH:LBB[0-9]+_[0-9]+]] 105 106; CHECK: [[FAILED]]: 107; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}} 108 109; verify the preheader is simplified by simplifycfg. 110; CHECK: [[PH]]: 111; CHECK: orr w22, wzr, #0x2 112; CHECK-NOT: orr w22, wzr, #0x4 113; CHECK-NOT: cmn w22, #4 114; CHECK: b [[LOOP2:LBB[0-9]+_[0-9]+]] 115; CHECK-NOT: b.ne [[LOOP2]] 116; CHECK-NOT: b {{LBB[0-9]+_[0-9]+}} 117; CHECK: bl _foo 118entry: 119 %pair = cmpxchg i32* %c, i32 %a, i32 %b seq_cst seq_cst 120 %success = extractvalue { i32, i1 } %pair, 1 121 br label %for.cond 122 123for.cond: ; preds = %if.end, %entry 124 %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ] 125 %changed.0.off0 = phi i1 [ %success, %entry ], [ %changed.1.off0, %if.end ] 126 %dec = add nsw i32 %i.0, -1 127 %tobool = icmp eq i32 %i.0, 0 128 br i1 %tobool, label %for.cond.cleanup, label %for.body 129 130for.cond.cleanup: ; preds = %for.cond 131 %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ] 132 ret i1 %changed.0.off0.lcssa 133 134for.body: ; preds = %for.cond 135 %or = or i32 %a, %b 136 %idxprom = sext i32 %dec to i64 137 %arrayidx = getelementptr inbounds i32, i32* %c, i64 %idxprom 138 %0 = load i32, i32* %arrayidx, align 4 139 %cmp = icmp eq i32 %or, %0 140 br i1 %cmp, label %if.end, label %if.then 141 142if.then: ; preds = %for.body 143 store i32 %or, i32* %arrayidx, align 4 144 tail call void @foo() 145 br label %if.end 146 147if.end: ; preds = %for.body, %if.then 148 %changed.1.off0 = phi i1 [ false, %if.then ], [ %changed.0.off0, %for.body ] 149 br label %for.cond 150} 151 152declare void @foo() 153