1; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s 2 3; Note that this should be refactored (for efficiency if nothing else) 4; when the PCS is implemented so we don't have to worry about the 5; loads and stores. 6 7@var_i32 = global i32 42 8@var_i64 = global i64 0 9 10; Add pure 12-bit immediates: 11define void @add_small() { 12; CHECK: add_small: 13 14; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, #4095 15 %val32 = load i32* @var_i32 16 %newval32 = add i32 %val32, 4095 17 store i32 %newval32, i32* @var_i32 18 19; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, #52 20 %val64 = load i64* @var_i64 21 %newval64 = add i64 %val64, 52 22 store i64 %newval64, i64* @var_i64 23 24 ret void 25} 26 27; Add 12-bit immediates, shifted left by 12 bits 28define void @add_med() { 29; CHECK: add_med: 30 31; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, #3567, lsl #12 32 %val32 = load i32* @var_i32 33 %newval32 = add i32 %val32, 14610432 ; =0xdef000 34 store i32 %newval32, i32* @var_i32 35 36; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, #4095, lsl #12 37 %val64 = load i64* @var_i64 38 %newval64 = add i64 %val64, 16773120 ; =0xfff000 39 store i64 %newval64, i64* @var_i64 40 41 ret void 42} 43 44; Subtract 12-bit immediates 45define void @sub_small() { 46; CHECK: sub_small: 47 48; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, #4095 49 %val32 = load i32* @var_i32 50 %newval32 = sub i32 %val32, 4095 51 store i32 %newval32, i32* @var_i32 52 53; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, #52 54 %val64 = load i64* @var_i64 55 %newval64 = sub i64 %val64, 52 56 store i64 %newval64, i64* @var_i64 57 58 ret void 59} 60 61; Subtract 12-bit immediates, shifted left by 12 bits 62define void @sub_med() { 63; CHECK: sub_med: 64 65; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, #3567, lsl #12 66 %val32 = load i32* @var_i32 67 %newval32 = sub i32 %val32, 14610432 ; =0xdef000 68 store i32 %newval32, i32* @var_i32 69 70; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, #4095, lsl #12 71 %val64 = load i64* @var_i64 72 %newval64 = sub i64 %val64, 16773120 ; =0xfff000 73 store i64 %newval64, i64* @var_i64 74 75 ret void 76} 77 78define void @testing() { 79; CHECK: testing: 80 %val = load i32* @var_i32 81 82; CHECK: cmp {{w[0-9]+}}, #4095 83; CHECK: b.ne .LBB4_6 84 %cmp_pos_small = icmp ne i32 %val, 4095 85 br i1 %cmp_pos_small, label %ret, label %test2 86 87test2: 88; CHECK: cmp {{w[0-9]+}}, #3567, lsl #12 89; CHECK: b.lo .LBB4_6 90 %newval2 = add i32 %val, 1 91 store i32 %newval2, i32* @var_i32 92 %cmp_pos_big = icmp ult i32 %val, 14610432 93 br i1 %cmp_pos_big, label %ret, label %test3 94 95test3: 96; CHECK: cmp {{w[0-9]+}}, #123 97; CHECK: b.lt .LBB4_6 98 %newval3 = add i32 %val, 2 99 store i32 %newval3, i32* @var_i32 100 %cmp_pos_slt = icmp slt i32 %val, 123 101 br i1 %cmp_pos_slt, label %ret, label %test4 102 103test4: 104; CHECK: cmp {{w[0-9]+}}, #321 105; CHECK: b.gt .LBB4_6 106 %newval4 = add i32 %val, 3 107 store i32 %newval4, i32* @var_i32 108 %cmp_pos_sgt = icmp sgt i32 %val, 321 109 br i1 %cmp_pos_sgt, label %ret, label %test5 110 111test5: 112; CHECK: cmn {{w[0-9]+}}, #444 113; CHECK: b.gt .LBB4_6 114 %newval5 = add i32 %val, 4 115 store i32 %newval5, i32* @var_i32 116 %cmp_neg_uge = icmp sgt i32 %val, -444 117 br i1 %cmp_neg_uge, label %ret, label %test6 118 119test6: 120 %newval6 = add i32 %val, 5 121 store i32 %newval6, i32* @var_i32 122 ret void 123 124ret: 125 ret void 126} 127; TODO: adds/subs 128