2014-05-24 14:50:23 +02:00
|
|
|
; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-linux-gnu | FileCheck %s
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
; Note that this should be refactored (for efficiency if nothing else)
|
|
|
|
; when the PCS is implemented so we don't have to worry about the
|
|
|
|
; loads and stores.
|
|
|
|
|
|
|
|
@var_i32 = global i32 42
|
2016-05-05 17:39:18 +02:00
|
|
|
@var2_i32 = global i32 43
|
2013-01-31 13:12:40 +01:00
|
|
|
@var_i64 = global i64 0
|
|
|
|
|
|
|
|
; Add pure 12-bit immediates:
|
|
|
|
define void @add_small() {
|
2013-07-14 08:24:09 +02:00
|
|
|
; CHECK-LABEL: add_small:
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, #4095
|
2015-02-27 22:17:42 +01:00
|
|
|
%val32 = load i32, i32* @var_i32
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval32 = add i32 %val32, 4095
|
|
|
|
store i32 %newval32, i32* @var_i32
|
|
|
|
|
|
|
|
; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, #52
|
2015-02-27 22:17:42 +01:00
|
|
|
%val64 = load i64, i64* @var_i64
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval64 = add i64 %val64, 52
|
|
|
|
store i64 %newval64, i64* @var_i64
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-03-31 02:31:13 +02:00
|
|
|
; Make sure we grab the imm variant when the register operand
|
|
|
|
; can be implicitly zero-extend.
|
|
|
|
; We used to generate something horrible like this:
|
|
|
|
; wA = ldrb
|
|
|
|
; xB = ldimm 12
|
|
|
|
; xC = add xB, wA, uxtb
|
|
|
|
; whereas this can be achieved with:
|
|
|
|
; wA = ldrb
|
|
|
|
; xC = add xA, #12 ; <- xA implicitly zero extend wA.
|
|
|
|
define void @add_small_imm(i8* %p, i64* %q, i32 %b, i32* %addr) {
|
|
|
|
; CHECK-LABEL: add_small_imm:
|
|
|
|
entry:
|
|
|
|
|
|
|
|
; CHECK: ldrb w[[LOAD32:[0-9]+]], [x0]
|
|
|
|
%t = load i8, i8* %p
|
|
|
|
%promoted = zext i8 %t to i64
|
|
|
|
%zextt = zext i8 %t to i32
|
|
|
|
%add = add nuw i32 %zextt, %b
|
|
|
|
|
|
|
|
; CHECK: add [[ADD2:x[0-9]+]], x[[LOAD32]], #12
|
|
|
|
%add2 = add nuw i64 %promoted, 12
|
|
|
|
store i32 %add, i32* %addr
|
|
|
|
|
|
|
|
; CHECK: str [[ADD2]], [x1]
|
|
|
|
store i64 %add2, i64* %q
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2013-01-31 13:12:40 +01:00
|
|
|
; Add 12-bit immediates, shifted left by 12 bits
|
|
|
|
define void @add_med() {
|
2013-07-14 08:24:09 +02:00
|
|
|
; CHECK-LABEL: add_med:
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{#3567, lsl #12|#14610432}}
|
2015-02-27 22:17:42 +01:00
|
|
|
%val32 = load i32, i32* @var_i32
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval32 = add i32 %val32, 14610432 ; =0xdef000
|
|
|
|
store i32 %newval32, i32* @var_i32
|
|
|
|
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{#4095, lsl #12|#16773120}}
|
2015-02-27 22:17:42 +01:00
|
|
|
%val64 = load i64, i64* @var_i64
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval64 = add i64 %val64, 16773120 ; =0xfff000
|
|
|
|
store i64 %newval64, i64* @var_i64
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Subtract 12-bit immediates
|
|
|
|
define void @sub_small() {
|
2013-07-14 08:24:09 +02:00
|
|
|
; CHECK-LABEL: sub_small:
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, #4095
|
2015-02-27 22:17:42 +01:00
|
|
|
%val32 = load i32, i32* @var_i32
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval32 = sub i32 %val32, 4095
|
|
|
|
store i32 %newval32, i32* @var_i32
|
|
|
|
|
|
|
|
; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, #52
|
2015-02-27 22:17:42 +01:00
|
|
|
%val64 = load i64, i64* @var_i64
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval64 = sub i64 %val64, 52
|
|
|
|
store i64 %newval64, i64* @var_i64
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Subtract 12-bit immediates, shifted left by 12 bits
|
|
|
|
define void @sub_med() {
|
2013-07-14 08:24:09 +02:00
|
|
|
; CHECK-LABEL: sub_med:
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, {{#3567, lsl #12|#14610432}}
|
2015-02-27 22:17:42 +01:00
|
|
|
%val32 = load i32, i32* @var_i32
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval32 = sub i32 %val32, 14610432 ; =0xdef000
|
|
|
|
store i32 %newval32, i32* @var_i32
|
|
|
|
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, {{#4095, lsl #12|#16773120}}
|
2015-02-27 22:17:42 +01:00
|
|
|
%val64 = load i64, i64* @var_i64
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval64 = sub i64 %val64, 16773120 ; =0xfff000
|
|
|
|
store i64 %newval64, i64* @var_i64
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @testing() {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: testing:
|
2015-02-27 22:17:42 +01:00
|
|
|
%val = load i32, i32* @var_i32
|
2016-05-05 17:39:18 +02:00
|
|
|
%val2 = load i32, i32* @var2_i32
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
; CHECK: cmp {{w[0-9]+}}, #4095
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: b.ne [[RET:.?LBB[0-9]+_[0-9]+]]
|
2013-01-31 13:12:40 +01:00
|
|
|
%cmp_pos_small = icmp ne i32 %val, 4095
|
|
|
|
br i1 %cmp_pos_small, label %ret, label %test2
|
|
|
|
|
|
|
|
test2:
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: cmp {{w[0-9]+}}, {{#3567, lsl #12|#14610432}}
|
2014-04-30 15:14:03 +02:00
|
|
|
; CHECK: b.lo [[RET]]
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval2 = add i32 %val, 1
|
|
|
|
store i32 %newval2, i32* @var_i32
|
2016-05-05 17:39:18 +02:00
|
|
|
%cmp_pos_big = icmp ult i32 %val2, 14610432
|
2013-01-31 13:12:40 +01:00
|
|
|
br i1 %cmp_pos_big, label %ret, label %test3
|
|
|
|
|
|
|
|
test3:
|
|
|
|
; CHECK: cmp {{w[0-9]+}}, #123
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: b.lt [[RET]]
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval3 = add i32 %val, 2
|
|
|
|
store i32 %newval3, i32* @var_i32
|
|
|
|
%cmp_pos_slt = icmp slt i32 %val, 123
|
|
|
|
br i1 %cmp_pos_slt, label %ret, label %test4
|
|
|
|
|
|
|
|
test4:
|
|
|
|
; CHECK: cmp {{w[0-9]+}}, #321
|
2014-04-14 14:50:41 +02:00
|
|
|
; CHECK: b.gt [[RET]]
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval4 = add i32 %val, 3
|
|
|
|
store i32 %newval4, i32* @var_i32
|
2016-05-05 17:39:18 +02:00
|
|
|
%cmp_pos_sgt = icmp sgt i32 %val2, 321
|
2013-01-31 13:12:40 +01:00
|
|
|
br i1 %cmp_pos_sgt, label %ret, label %test5
|
|
|
|
|
|
|
|
test5:
|
|
|
|
; CHECK: cmn {{w[0-9]+}}, #444
|
2017-01-11 20:55:19 +01:00
|
|
|
; CHECK: b.gt [[RET]]
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval5 = add i32 %val, 4
|
|
|
|
store i32 %newval5, i32* @var_i32
|
2016-05-05 17:39:18 +02:00
|
|
|
%cmp_neg_uge = icmp sgt i32 %val2, -444
|
2013-01-31 13:12:40 +01:00
|
|
|
br i1 %cmp_neg_uge, label %ret, label %test6
|
|
|
|
|
|
|
|
test6:
|
|
|
|
%newval6 = add i32 %val, 5
|
|
|
|
store i32 %newval6, i32* @var_i32
|
|
|
|
ret void
|
|
|
|
|
|
|
|
ret:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
; TODO: adds/subs
|