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 4target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 5target triple = "aarch64--" 6 7define i32 @cse_gep([4 x i32]* %ptr, i32 %idx) { 8 ; O0-LABEL: name: cse_gep 9 ; O0: bb.1 (%ir-block.0): 10 ; O0: liveins: $w1, $x0 11 ; O0: [[COPY:%[0-9]+]]:_(p0) = COPY $x0 12 ; O0: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1 13 ; O0: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY1]](s32) 14 ; O0: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16 15 ; O0: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]] 16 ; O0: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64) 17 ; O0: [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0) 18 ; O0: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[COPY2]](p0) :: (load 4 from %ir.gep1) 19 ; O0: [[MUL1:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]] 20 ; O0: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL1]](s64) 21 ; O0: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4 22 ; O0: [[PTR_ADD2:%[0-9]+]]:_(p0) = G_PTR_ADD [[PTR_ADD1]], [[C1]](s64) 23 ; O0: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD2]](p0) :: (load 4 from %ir.gep2) 24 ; O0: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[LOAD1]], [[LOAD1]] 25 ; O0: $w0 = COPY [[ADD]](s32) 26 ; O0: RET_ReallyLR implicit $w0 27 ; O3-LABEL: name: cse_gep 28 ; O3: bb.1 (%ir-block.0): 29 ; O3: liveins: $w1, $x0 30 ; O3: [[COPY:%[0-9]+]]:_(p0) = COPY $x0 31 ; O3: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1 32 ; O3: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY1]](s32) 33 ; O3: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16 34 ; O3: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[SEXT]], [[C]] 35 ; O3: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[MUL]](s64) 36 ; O3: [[COPY2:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0) 37 ; O3: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[COPY2]](p0) :: (load 4 from %ir.gep1) 38 ; O3: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4 39 ; O3: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[PTR_ADD]], [[C1]](s64) 40 ; O3: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD1]](p0) :: (load 4 from %ir.gep2) 41 ; O3: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[LOAD1]], [[LOAD1]] 42 ; O3: $w0 = COPY [[ADD]](s32) 43 ; O3: RET_ReallyLR implicit $w0 44 %sidx = sext i32 %idx to i64 45 %gep1 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 %sidx, i64 0 46 %v1 = load i32, i32* %gep1 47 %gep2 = getelementptr inbounds [4 x i32], [4 x i32]* %ptr, i64 %sidx, i64 1 48 %v2 = load i32, i32* %gep2 49 %res = add i32 %v2, %v2 50 ret i32 %res 51} 52