1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; RUN: llc -O0 -stop-after=irtranslator -global-isel -verify-machineinstrs %s -o - 2>&1 | FileCheck %s --check-prefix=O0
3 ; RUN: llc -O3 -stop-after=irtranslator -global-isel -verify-machineinstrs %s -o - 2>&1 | FileCheck %s --check-prefix=O3
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5 target triple = "aarch64--"
7 define i32 @cse_gep(ptr %ptr, i32 %idx) {
8 ; O0-LABEL: name: cse_gep
9 ; O0: bb.1 (%ir-block.0):
10 ; O0-NEXT: liveins: $w1, $x0
12 ; O0-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
13 ; O0-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
14 ; O0-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY1]](s32)
15 ; O0-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
16 ; O0-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]]
17 ; O0-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64)
18 ; O0-NEXT: [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
19 ; O0-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[COPY2]](p0) :: (load (s32) from %ir.gep1)
20 ; O0-NEXT: [[MUL1:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]]
21 ; O0-NEXT: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL1]](s64)
22 ; O0-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
23 ; O0-NEXT: %11:_(p0) = nuw nusw G_PTR_ADD [[PTR_ADD1]], [[C1]](s64)
24 ; O0-NEXT: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD %11(p0) :: (load (s32) from %ir.gep2)
25 ; O0-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[LOAD]], [[LOAD1]]
26 ; O0-NEXT: $w0 = COPY [[ADD]](s32)
27 ; O0-NEXT: RET_ReallyLR implicit $w0
29 ; O3-LABEL: name: cse_gep
30 ; O3: bb.1 (%ir-block.0):
31 ; O3-NEXT: liveins: $w1, $x0
33 ; O3-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
34 ; O3-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
35 ; O3-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY1]](s32)
36 ; O3-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
37 ; O3-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]]
38 ; O3-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64)
39 ; O3-NEXT: [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
40 ; O3-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[COPY2]](p0) :: (load (s32) from %ir.gep1)
41 ; O3-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
42 ; O3-NEXT: %9:_(p0) = nuw nusw G_PTR_ADD [[PTR_ADD]], [[C1]](s64)
43 ; O3-NEXT: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD %9(p0) :: (load (s32) from %ir.gep2)
44 ; O3-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[LOAD]], [[LOAD1]]
45 ; O3-NEXT: $w0 = COPY [[ADD]](s32)
46 ; O3-NEXT: RET_ReallyLR implicit $w0
47 %sidx = sext i32 %idx to i64
48 %gep1 = getelementptr inbounds [4 x i32], ptr %ptr, i64 %sidx, i64 0
49 %v1 = load i32, ptr %gep1
50 %gep2 = getelementptr inbounds [4 x i32], ptr %ptr, i64 %sidx, i64 1
51 %v2 = load i32, ptr %gep2
52 %res = add i32 %v1, %v2
56 ; OSS Fuzz https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65052
57 define void @ossfuzz65052() {
58 ; O0-LABEL: name: ossfuzz65052
59 ; O0: bb.1 (%ir-block.0):
60 ; O0-NEXT: successors: %bb.2(0x80000000)
62 ; O0-NEXT: [[DEF:%[0-9]+]]:_(p0) = G_IMPLICIT_DEF
63 ; O0-NEXT: [[C:%[0-9]+]]:_(s128) = G_CONSTANT i128 -170141183460469231731687303715884105728
64 ; O0-NEXT: [[TRUNC:%[0-9]+]]:_(s64) = G_TRUNC [[C]](s128)
65 ; O0-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
66 ; O0-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[TRUNC]], [[C1]]
67 ; O0-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[DEF]], [[MUL]](s64)
68 ; O0-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
72 ; O0-NEXT: successors: %bb.2(0x80000000)
76 ; O3-LABEL: name: ossfuzz65052
77 ; O3: bb.1 (%ir-block.0):
78 ; O3-NEXT: successors: %bb.2(0x80000000)
80 ; O3-NEXT: [[DEF:%[0-9]+]]:_(p0) = G_IMPLICIT_DEF
81 ; O3-NEXT: [[C:%[0-9]+]]:_(s128) = G_CONSTANT i128 -170141183460469231731687303715884105728
82 ; O3-NEXT: [[TRUNC:%[0-9]+]]:_(s64) = G_TRUNC [[C]](s128)
83 ; O3-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
84 ; O3-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[TRUNC]], [[C1]]
85 ; O3-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[DEF]], [[MUL]](s64)
86 ; O3-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
89 ; O3-NEXT: successors: %bb.2(0x80000000)
92 %G15 = getelementptr i128, ptr poison, i128 -170141183460469231731687303715884105728