; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA32
; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA64

define i32 @m_offset_neg_2049(ptr %p) nounwind {
; LA32-LABEL: m_offset_neg_2049:
; LA32:       # %bb.0:
; LA32-NEXT:    addi.w $a0, $a0, -2048
; LA32-NEXT:    addi.w $a0, $a0, -1
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, 0
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_neg_2049:
; LA64:       # %bb.0:
; LA64-NEXT:    addi.d $a0, $a0, -2048
; LA64-NEXT:    addi.d $a0, $a0, -1
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, 0
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = getelementptr inbounds i8, ptr %p, i32 -2049
  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
  ret i32 %2
}

define i32 @m_offset_neg_2048(ptr %p) nounwind {
; LA32-LABEL: m_offset_neg_2048:
; LA32:       # %bb.0:
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, -2048
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_neg_2048:
; LA64:       # %bb.0:
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, -2048
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = getelementptr inbounds i8, ptr %p, i32 -2048
  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
  ret i32 %2
}

define i32 @m_offset_neg_1(ptr %p) nounwind {
; LA32-LABEL: m_offset_neg_1:
; LA32:       # %bb.0:
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, -1
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_neg_1:
; LA64:       # %bb.0:
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, -1
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = getelementptr inbounds i8, ptr %p, i32 -1
  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
  ret i32 %2
}

define i32 @m_offset_0(ptr %p) nounwind {
; LA32-LABEL: m_offset_0:
; LA32:       # %bb.0:
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, 0
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_0:
; LA64:       # %bb.0:
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, 0
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %p)
  ret i32 %1
}

define i32 @m_offset_1(ptr %p) nounwind {
; LA32-LABEL: m_offset_1:
; LA32:       # %bb.0:
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, 1
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_1:
; LA64:       # %bb.0:
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, 1
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = getelementptr inbounds i8, ptr %p, i32 1
  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
  ret i32 %2
}

define i32 @m_offset_2047(ptr %p) nounwind {
; LA32-LABEL: m_offset_2047:
; LA32:       # %bb.0:
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, 2047
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_2047:
; LA64:       # %bb.0:
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, 2047
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = getelementptr inbounds i8, ptr %p, i32 2047
  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
  ret i32 %2
}

define i32 @m_offset_2048(ptr %p) nounwind {
; LA32-LABEL: m_offset_2048:
; LA32:       # %bb.0:
; LA32-NEXT:    addi.w $a0, $a0, 2047
; LA32-NEXT:    addi.w $a0, $a0, 1
; LA32-NEXT:    #APP
; LA32-NEXT:    ld.w $a0, $a0, 0
; LA32-NEXT:    #NO_APP
; LA32-NEXT:    ret
;
; LA64-LABEL: m_offset_2048:
; LA64:       # %bb.0:
; LA64-NEXT:    addi.d $a0, $a0, 2047
; LA64-NEXT:    addi.d $a0, $a0, 1
; LA64-NEXT:    #APP
; LA64-NEXT:    ld.w $a0, $a0, 0
; LA64-NEXT:    #NO_APP
; LA64-NEXT:    ret
  %1 = getelementptr inbounds i8, ptr %p, i32 2048
  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
  ret i32 %2
}
