1*0a6a1f1dSLionel Sambuc; RUN: llc -march=arm64 < %s | FileCheck %s 2*0a6a1f1dSLionel Sambuc; rdar://10232252 3*0a6a1f1dSLionel Sambuc 4*0a6a1f1dSLionel Sambuc@object = external hidden global i64, section "__DATA, __objc_ivar", align 8 5*0a6a1f1dSLionel Sambuc 6*0a6a1f1dSLionel Sambuc; base + offset (imm9) 7*0a6a1f1dSLionel Sambuc; CHECK: @t1 8*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [x{{[0-9]+}}, #8] 9*0a6a1f1dSLionel Sambuc; CHECK: ret 10*0a6a1f1dSLionel Sambucdefine void @t1() { 11*0a6a1f1dSLionel Sambuc %incdec.ptr = getelementptr inbounds i64* @object, i64 1 12*0a6a1f1dSLionel Sambuc %tmp = load volatile i64* %incdec.ptr, align 8 13*0a6a1f1dSLionel Sambuc ret void 14*0a6a1f1dSLionel Sambuc} 15*0a6a1f1dSLionel Sambuc 16*0a6a1f1dSLionel Sambuc; base + offset (> imm9) 17*0a6a1f1dSLionel Sambuc; CHECK: @t2 18*0a6a1f1dSLionel Sambuc; CHECK: sub [[ADDREG:x[0-9]+]], x{{[0-9]+}}, #264 19*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [ 20*0a6a1f1dSLionel Sambuc; CHECK: [[ADDREG]]] 21*0a6a1f1dSLionel Sambuc; CHECK: ret 22*0a6a1f1dSLionel Sambucdefine void @t2() { 23*0a6a1f1dSLionel Sambuc %incdec.ptr = getelementptr inbounds i64* @object, i64 -33 24*0a6a1f1dSLionel Sambuc %tmp = load volatile i64* %incdec.ptr, align 8 25*0a6a1f1dSLionel Sambuc ret void 26*0a6a1f1dSLionel Sambuc} 27*0a6a1f1dSLionel Sambuc 28*0a6a1f1dSLionel Sambuc; base + unsigned offset (> imm9 and <= imm12 * size of type in bytes) 29*0a6a1f1dSLionel Sambuc; CHECK: @t3 30*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [x{{[0-9]+}}, #32760] 31*0a6a1f1dSLionel Sambuc; CHECK: ret 32*0a6a1f1dSLionel Sambucdefine void @t3() { 33*0a6a1f1dSLionel Sambuc %incdec.ptr = getelementptr inbounds i64* @object, i64 4095 34*0a6a1f1dSLionel Sambuc %tmp = load volatile i64* %incdec.ptr, align 8 35*0a6a1f1dSLionel Sambuc ret void 36*0a6a1f1dSLionel Sambuc} 37*0a6a1f1dSLionel Sambuc 38*0a6a1f1dSLionel Sambuc; base + unsigned offset (> imm12 * size of type in bytes) 39*0a6a1f1dSLionel Sambuc; CHECK: @t4 40*0a6a1f1dSLionel Sambuc; CHECK: orr w[[NUM:[0-9]+]], wzr, #0x8000 41*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [x{{[0-9]+}}, x[[NUM]]] 42*0a6a1f1dSLionel Sambuc; CHECK: ret 43*0a6a1f1dSLionel Sambucdefine void @t4() { 44*0a6a1f1dSLionel Sambuc %incdec.ptr = getelementptr inbounds i64* @object, i64 4096 45*0a6a1f1dSLionel Sambuc %tmp = load volatile i64* %incdec.ptr, align 8 46*0a6a1f1dSLionel Sambuc ret void 47*0a6a1f1dSLionel Sambuc} 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc; base + reg 50*0a6a1f1dSLionel Sambuc; CHECK: @t5 51*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [x{{[0-9]+}}, x{{[0-9]+}}, lsl #3] 52*0a6a1f1dSLionel Sambuc; CHECK: ret 53*0a6a1f1dSLionel Sambucdefine void @t5(i64 %a) { 54*0a6a1f1dSLionel Sambuc %incdec.ptr = getelementptr inbounds i64* @object, i64 %a 55*0a6a1f1dSLionel Sambuc %tmp = load volatile i64* %incdec.ptr, align 8 56*0a6a1f1dSLionel Sambuc ret void 57*0a6a1f1dSLionel Sambuc} 58*0a6a1f1dSLionel Sambuc 59*0a6a1f1dSLionel Sambuc; base + reg + imm 60*0a6a1f1dSLionel Sambuc; CHECK: @t6 61*0a6a1f1dSLionel Sambuc; CHECK: add [[ADDREG:x[0-9]+]], x{{[0-9]+}}, x{{[0-9]+}}, lsl #3 62*0a6a1f1dSLionel Sambuc; CHECK-NEXT: orr w[[NUM:[0-9]+]], wzr, #0x8000 63*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [x{{[0-9]+}}, x[[NUM]]] 64*0a6a1f1dSLionel Sambuc; CHECK: ret 65*0a6a1f1dSLionel Sambucdefine void @t6(i64 %a) { 66*0a6a1f1dSLionel Sambuc %tmp1 = getelementptr inbounds i64* @object, i64 %a 67*0a6a1f1dSLionel Sambuc %incdec.ptr = getelementptr inbounds i64* %tmp1, i64 4096 68*0a6a1f1dSLionel Sambuc %tmp = load volatile i64* %incdec.ptr, align 8 69*0a6a1f1dSLionel Sambuc ret void 70*0a6a1f1dSLionel Sambuc} 71*0a6a1f1dSLionel Sambuc 72*0a6a1f1dSLionel Sambuc; Test base + wide immediate 73*0a6a1f1dSLionel Sambucdefine void @t7(i64 %a) { 74*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t7: 75*0a6a1f1dSLionel Sambuc; CHECK: orr w[[NUM:[0-9]+]], wzr, #0xffff 76*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, [x0, x[[NUM]]] 77*0a6a1f1dSLionel Sambuc %1 = add i64 %a, 65535 ;0xffff 78*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 79*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 80*0a6a1f1dSLionel Sambuc ret void 81*0a6a1f1dSLionel Sambuc} 82*0a6a1f1dSLionel Sambuc 83*0a6a1f1dSLionel Sambucdefine void @t8(i64 %a) { 84*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t8: 85*0a6a1f1dSLionel Sambuc; CHECK: movn [[REG:x[0-9]+]], #0x1235 86*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, [x0, [[REG]]] 87*0a6a1f1dSLionel Sambuc %1 = sub i64 %a, 4662 ;-4662 is 0xffffffffffffedca 88*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 89*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 90*0a6a1f1dSLionel Sambuc ret void 91*0a6a1f1dSLionel Sambuc} 92*0a6a1f1dSLionel Sambuc 93*0a6a1f1dSLionel Sambucdefine void @t9(i64 %a) { 94*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t9: 95*0a6a1f1dSLionel Sambuc; CHECK: movn [[REG:x[0-9]+]], #0x1235, lsl #16 96*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, [x0, [[REG]]] 97*0a6a1f1dSLionel Sambuc %1 = add i64 -305463297, %a ;-305463297 is 0xffffffffedcaffff 98*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 99*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 100*0a6a1f1dSLionel Sambuc ret void 101*0a6a1f1dSLionel Sambuc} 102*0a6a1f1dSLionel Sambuc 103*0a6a1f1dSLionel Sambucdefine void @t10(i64 %a) { 104*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t10: 105*0a6a1f1dSLionel Sambuc; CHECK: movz [[REG:x[0-9]+]], #0x123, lsl #48 106*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, [x0, [[REG]]] 107*0a6a1f1dSLionel Sambuc %1 = add i64 %a, 81909218222800896 ;0x123000000000000 108*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 109*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 110*0a6a1f1dSLionel Sambuc ret void 111*0a6a1f1dSLionel Sambuc} 112*0a6a1f1dSLionel Sambuc 113*0a6a1f1dSLionel Sambucdefine void @t11(i64 %a) { 114*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t11: 115*0a6a1f1dSLionel Sambuc; CHECK: movz w[[NUM:[0-9]+]], #0x123, lsl #16 116*0a6a1f1dSLionel Sambuc; CHECK: movk w[[NUM:[0-9]+]], #0x4567 117*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, [x0, x[[NUM]]] 118*0a6a1f1dSLionel Sambuc %1 = add i64 %a, 19088743 ;0x1234567 119*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 120*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 121*0a6a1f1dSLionel Sambuc ret void 122*0a6a1f1dSLionel Sambuc} 123*0a6a1f1dSLionel Sambuc 124*0a6a1f1dSLionel Sambuc; Test some boundaries that should not use movz/movn/orr 125*0a6a1f1dSLionel Sambucdefine void @t12(i64 %a) { 126*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t12: 127*0a6a1f1dSLionel Sambuc; CHECK: add [[REG:x[0-9]+]], x0, #4095 128*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, {{\[}}[[REG]]] 129*0a6a1f1dSLionel Sambuc %1 = add i64 %a, 4095 ;0xfff 130*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 131*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 132*0a6a1f1dSLionel Sambuc ret void 133*0a6a1f1dSLionel Sambuc} 134*0a6a1f1dSLionel Sambuc 135*0a6a1f1dSLionel Sambucdefine void @t13(i64 %a) { 136*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t13: 137*0a6a1f1dSLionel Sambuc; CHECK: sub [[REG:x[0-9]+]], x0, #4095 138*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, {{\[}}[[REG]]] 139*0a6a1f1dSLionel Sambuc %1 = add i64 %a, -4095 ;-0xfff 140*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 141*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 142*0a6a1f1dSLionel Sambuc ret void 143*0a6a1f1dSLionel Sambuc} 144*0a6a1f1dSLionel Sambuc 145*0a6a1f1dSLionel Sambucdefine void @t14(i64 %a) { 146*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t14: 147*0a6a1f1dSLionel Sambuc; CHECK: add [[REG:x[0-9]+]], x0, #291, lsl #12 148*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, {{\[}}[[REG]]] 149*0a6a1f1dSLionel Sambuc %1 = add i64 %a, 1191936 ;0x123000 150*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 151*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 152*0a6a1f1dSLionel Sambuc ret void 153*0a6a1f1dSLionel Sambuc} 154*0a6a1f1dSLionel Sambuc 155*0a6a1f1dSLionel Sambucdefine void @t15(i64 %a) { 156*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t15: 157*0a6a1f1dSLionel Sambuc; CHECK: sub [[REG:x[0-9]+]], x0, #291, lsl #12 158*0a6a1f1dSLionel Sambuc; CHECK-NEXT: ldr xzr, {{\[}}[[REG]]] 159*0a6a1f1dSLionel Sambuc %1 = add i64 %a, -1191936 ;0xFFFFFFFFFFEDD000 160*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 161*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 162*0a6a1f1dSLionel Sambuc ret void 163*0a6a1f1dSLionel Sambuc} 164*0a6a1f1dSLionel Sambuc 165*0a6a1f1dSLionel Sambucdefine void @t16(i64 %a) { 166*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t16: 167*0a6a1f1dSLionel Sambuc; CHECK: ldr xzr, [x0, #28672] 168*0a6a1f1dSLionel Sambuc %1 = add i64 %a, 28672 ;0x7000 169*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 170*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 171*0a6a1f1dSLionel Sambuc ret void 172*0a6a1f1dSLionel Sambuc} 173*0a6a1f1dSLionel Sambuc 174*0a6a1f1dSLionel Sambucdefine void @t17(i64 %a) { 175*0a6a1f1dSLionel Sambuc; CHECK-LABEL: t17: 176*0a6a1f1dSLionel Sambuc; CHECK: ldur xzr, [x0, #-256] 177*0a6a1f1dSLionel Sambuc %1 = add i64 %a, -256 ;-0x100 178*0a6a1f1dSLionel Sambuc %2 = inttoptr i64 %1 to i64* 179*0a6a1f1dSLionel Sambuc %3 = load volatile i64* %2, align 8 180*0a6a1f1dSLionel Sambuc ret void 181*0a6a1f1dSLionel Sambuc} 182