llvm/llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReserve-StoreCond.ll

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
; RUN:   -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-64
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
; RUN:   -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-64
; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
; RUN:   -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-32
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
; RUN:   -mcpu=pwr8 < %s | FileCheck %s --check-prefix=CHECK-64

declare i32 @llvm.ppc.lwarx(ptr)
define dso_local signext i32 @test_lwarx(ptr readnone %a) {
; CHECK-64-LABEL: test_lwarx:
; CHECK-64:       # %bb.0: # %entry
; CHECK-64-NEXT:    #APP
; CHECK-64-NEXT:    lwarx 3, 0, 3
; CHECK-64-NEXT:    #NO_APP
; CHECK-64-NEXT:    extsw 3, 3
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: test_lwarx:
; CHECK-32:       # %bb.0: # %entry
; CHECK-32-NEXT:    #APP
; CHECK-32-NEXT:    lwarx 3, 0, 3
; CHECK-32-NEXT:    #NO_APP
; CHECK-32-NEXT:    blr
entry:
  %0 = call i32 asm sideeffect "lwarx $0, ${1:y}", "=r,*Z,~{memory}"(ptr elementtype(i32) %a)
  ret i32 %0
}

declare i32 @llvm.ppc.stwcx(ptr, i32)
define dso_local signext i32 @test_stwcx(ptr %a, i32 signext %b) {
; CHECK-64-LABEL: test_stwcx:
; CHECK-64:       # %bb.0: # %entry
; CHECK-64-NEXT:    stwcx. 4, 0, 3
; CHECK-64-NEXT:    mfocrf 3, 128
; CHECK-64-NEXT:    srwi 3, 3, 28
; CHECK-64-NEXT:    rlwinm 3, 3, 31, 31, 31
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: test_stwcx:
; CHECK-32:       # %bb.0: # %entry
; CHECK-32-NEXT:    stwcx. 4, 0, 3
; CHECK-32-NEXT:    mfocrf 3, 128
; CHECK-32-NEXT:    srwi 3, 3, 28
; CHECK-32-NEXT:    rlwinm 3, 3, 31, 31, 31
; CHECK-32-NEXT:    blr
entry:
  %0 = tail call i32 @llvm.ppc.stwcx(ptr %a, i32 %b)
  ret i32 %0
}

declare i32 @llvm.ppc.sthcx(ptr, i32)
define dso_local signext i32 @test_sthcx(ptr %a, i16 signext %val) {
; CHECK-64-LABEL: test_sthcx:
; CHECK-64:       # %bb.0: # %entry
; CHECK-64-NEXT:    sthcx. 4, 0, 3
; CHECK-64-NEXT:    mfocrf 3, 128
; CHECK-64-NEXT:    srwi 3, 3, 28
; CHECK-64-NEXT:    rlwinm 3, 3, 31, 31, 31
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: test_sthcx:
; CHECK-32:       # %bb.0: # %entry
; CHECK-32-NEXT:    sthcx. 4, 0, 3
; CHECK-32-NEXT:    mfocrf 3, 128
; CHECK-32-NEXT:    srwi 3, 3, 28
; CHECK-32-NEXT:    rlwinm 3, 3, 31, 31, 31
; CHECK-32-NEXT:    blr
entry:
  %0 = sext i16 %val to i32
  %1 = tail call i32 @llvm.ppc.sthcx(ptr %a, i32 %0)
  ret i32 %1
}

declare i32 @llvm.ppc.stbcx(ptr, i32)
define signext i32 @test_stbcx(ptr %addr, i8 signext %val) {
; CHECK-64-LABEL: test_stbcx:
; CHECK-64:       # %bb.0: # %entry
; CHECK-64-NEXT:    stbcx. 4, 0, 3
; CHECK-64-NEXT:    mfocrf 3, 128
; CHECK-64-NEXT:    srwi 3, 3, 28
; CHECK-64-NEXT:    rlwinm 3, 3, 31, 31, 31
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: test_stbcx:
; CHECK-32:       # %bb.0: # %entry
; CHECK-32-NEXT:    stbcx. 4, 0, 3
; CHECK-32-NEXT:    mfocrf 3, 128
; CHECK-32-NEXT:    srwi 3, 3, 28
; CHECK-32-NEXT:    rlwinm 3, 3, 31, 31, 31
; CHECK-32-NEXT:    blr
entry:
  %conv = sext i8 %val to i32
  %0 = tail call i32 @llvm.ppc.stbcx(ptr %addr, i32 %conv)
  ret i32 %0
}

define dso_local signext i16 @test_lharx(ptr %a) {
; CHECK-64-LABEL: test_lharx:
; CHECK-64:       # %bb.0: # %entry
; CHECK-64-NEXT:    #APP
; CHECK-64-NEXT:    lharx 3, 0, 3
; CHECK-64-NEXT:    #NO_APP
; CHECK-64-NEXT:    extsh 3, 3
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: test_lharx:
; CHECK-32:       # %bb.0: # %entry
; CHECK-32-NEXT:    #APP
; CHECK-32-NEXT:    lharx 3, 0, 3
; CHECK-32-NEXT:    #NO_APP
; CHECK-32-NEXT:    extsh 3, 3
; CHECK-32-NEXT:    blr
entry:
  %0 = tail call i16 asm sideeffect "lharx $0, ${1:y}", "=r,*Z,~{memory}"(ptr elementtype(i16) %a)
  ret i16 %0
}

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @test_lbarx(ptr %a) {
; CHECK-64-LABEL: test_lbarx:
; CHECK-64:       # %bb.0: # %entry
; CHECK-64-NEXT:    #APP
; CHECK-64-NEXT:    lbarx 3, 0, 3
; CHECK-64-NEXT:    #NO_APP
; CHECK-64-NEXT:    clrldi 3, 3, 56
; CHECK-64-NEXT:    blr
;
; CHECK-32-LABEL: test_lbarx:
; CHECK-32:       # %bb.0: # %entry
; CHECK-32-NEXT:    #APP
; CHECK-32-NEXT:    lbarx 3, 0, 3
; CHECK-32-NEXT:    #NO_APP
; CHECK-32-NEXT:    clrlwi 3, 3, 24
; CHECK-32-NEXT:    blr
entry:
  %0 = tail call i8 asm sideeffect "lbarx $0, ${1:y}", "=r,*Z,~{memory}"(ptr elementtype(i8) %a)
  ret i8 %0
}