1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple=aarch64-- -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
4 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5 target triple = "aarch64"
7 @x = dso_local global i32 -32768, align 4
9 define dso_local i32 @check_sext_not_lost(i32* %ptr) {
11 %ptr.addr = alloca i32*, align 8
12 store i32* %ptr, i32** %ptr.addr, align 8
13 %0 = load i32*, i32** %ptr.addr, align 8
14 %1 = load i32, i32* @x, align 4
15 %sub = sub nsw i32 %1, 32768
16 %conv = trunc i32 %sub to i16
17 %idxprom = sext i16 %conv to i64
18 %arrayidx = getelementptr inbounds i32, i32* %0, i64 %idxprom
19 %2 = load i32, i32* %arrayidx, align 4
25 name: check_sext_not_lost
29 tracksRegLiveness: true
31 - { id: 0, class: gpr }
32 - { id: 1, class: gpr }
33 - { id: 2, class: gpr }
34 - { id: 3, class: gpr }
35 - { id: 4, class: gpr }
36 - { id: 5, class: gpr }
37 - { id: 6, class: gpr }
39 - { id: 8, class: gpr }
41 - { id: 10, class: gpr }
42 - { id: 11, class: gpr }
43 - { id: 12, class: _ }
44 - { id: 13, class: gpr }
45 - { id: 14, class: gpr }
46 - { id: 15, class: gpr64 }
47 - { id: 16, class: gpr }
54 - { id: 0, name: ptr.addr, size: 8, alignment: 8 }
55 machineFunctionInfo: {}
60 ; CHECK-LABEL: name: check_sext_not_lost
62 ; CHECK: [[COPY:%[0-9]+]]:gpr64all = COPY $x0
63 ; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY [[COPY]]
64 ; CHECK: STRXui [[COPY1]], %stack.0.ptr.addr, 0 :: (store (p0) into %ir.ptr.addr)
65 ; CHECK: [[LDRXui:%[0-9]+]]:gpr64common = LDRXui %stack.0.ptr.addr, 0 :: (dereferenceable load (p0) from %ir.ptr.addr)
66 ; CHECK: [[ADRP:%[0-9]+]]:gpr64common = ADRP target-flags(aarch64-page) @x
67 ; CHECK: [[LDRWui:%[0-9]+]]:gpr32common = LDRWui [[ADRP]], target-flags(aarch64-pageoff, aarch64-nc) @x :: (dereferenceable load (s32) from @x)
68 ; CHECK: [[SUBSWri:%[0-9]+]]:gpr32 = nsw SUBSWri [[LDRWui]], 8, 12, implicit-def $nzcv
69 ; CHECK: [[DEF:%[0-9]+]]:gpr64all = IMPLICIT_DEF
70 ; CHECK: [[INSERT_SUBREG:%[0-9]+]]:gpr64 = INSERT_SUBREG [[DEF]], [[SUBSWri]], %subreg.sub_32
71 ; CHECK: [[SBFMXri:%[0-9]+]]:gpr64 = SBFMXri [[INSERT_SUBREG]], 0, 15
72 ; CHECK: [[LDRWroX:%[0-9]+]]:gpr32 = LDRWroX [[LDRXui]], [[SBFMXri]], 0, 1 :: (load (s32) from %ir.arrayidx)
73 ; CHECK: $w0 = COPY [[LDRWroX]]
74 ; CHECK: RET_ReallyLR implicit $w0
76 %1:gpr(p0) = G_FRAME_INDEX %stack.0.ptr.addr
77 G_STORE %0(p0), %1(p0) :: (store (p0) into %ir.ptr.addr)
78 %2:gpr(p0) = G_LOAD %1(p0) :: (dereferenceable load (p0) from %ir.ptr.addr)
79 %15:gpr64(p0) = ADRP target-flags(aarch64-page) @x
80 %4:gpr(p0) = G_ADD_LOW %15(p0), target-flags(aarch64-pageoff, aarch64-nc) @x
81 %3:gpr(s32) = G_LOAD %4(p0) :: (dereferenceable load (s32) from @x)
82 %5:gpr(s32) = G_CONSTANT i32 32768
83 %6:gpr(s32) = nsw G_SUB %3, %5
84 %16:gpr(s64) = G_ANYEXT %6(s32)
85 %8:gpr(s64) = G_SEXT_INREG %16, 16
86 %14:gpr(s64) = G_CONSTANT i64 2
87 %10:gpr(s64) = G_SHL %8, %14(s64)
88 %11:gpr(p0) = G_PTR_ADD %2, %10(s64)
89 %13:gpr(s32) = G_LOAD %11(p0) :: (load (s32) from %ir.arrayidx)
91 RET_ReallyLR implicit $w0