brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 2dca387 Raw
126 lines · plain
1; RUN: llc -verify-machineinstrs -O3 -mcpu=pwr7 < %s | FileCheck %s2; RUN: llc -verify-machineinstrs -O3 -print-after=codegenprepare -mcpu=pwr7  < %s >%t 2>&1 && FileCheck --check-prefix=CHECK-UseAA <%t %s3target datalayout = "E-m:e-i64:64-n32:64"4target triple = "powerpc64-unknown-linux-gnu"5 6; Following test cases test enabling SeparateConstOffsetFromGEP pass in the PPC7; backend. If useAA() returns true, it will lower a GEP with multiple indices8; into GEPs with a single index, otherwise it will lower it into a9; "ptrtoint+arithmetics+inttoptr" form.10 11%struct = type { i32, i32, i32, i32, [20 x i32] }12 13; Check that when two complex GEPs are used in two basic blocks, LLVM can14; elimilate the common subexpression for the second use.15define void @test_GEP_CSE(ptr %string, ptr %adj, i32 %lib, i64 %idxprom) {16  %liberties = getelementptr [240 x %struct], ptr %string, i64 1, i64 %idxprom, i32 317  %1 = load i32, ptr %liberties, align 418  %cmp = icmp eq i32 %1, %lib19  br i1 %cmp, label %if.then, label %if.end20 21if.then:                                          ; preds = %entry22  %origin = getelementptr [240 x %struct], ptr %string, i64 1, i64 %idxprom, i32 223  %2 = load i32, ptr %origin, align 424  store i32 %2, ptr %adj, align 425  br label %if.end26 27if.end:                                           ; preds = %if.then, %entry28  ret void29}30 31; CHECK-UseAA-LABEL: @test_GEP_CSE(32; CHECK-UseAA: [[IDX:%[a-zA-Z0-9]+]] = mul i64 %idxprom, 9633; CHECK-UseAA: [[PTR1:%[a-zA-Z0-9]+]] = getelementptr i8, ptr %string, i64 [[IDX]]34; CHECK-UseAA: getelementptr i8, ptr [[PTR1]], i64 2305235; CHECK-UseAA: if.then:36; CHECK-UseAA: getelementptr i8, ptr [[PTR1]], i64 2304837 38%class.my = type { i32, [128 x i32], i32, [256 x %struct.pt]}39%struct.pt = type { ptr, i32, i32 }40%struct.point = type { i32, i32 }41 42; Check when a GEP is used across two basic block, LLVM can sink the address43; calculation and code gen can generate a better addressing mode for the second44; use.45define void @test_GEP_across_BB(ptr %this, i64 %idx) {46  %1 = getelementptr %class.my, ptr %this, i64 0, i32 3, i64 %idx, i32 147  %2 = load i32, ptr %1, align 448  %3 = getelementptr %class.my, ptr %this, i64 0, i32 3, i64 %idx, i32 249  %4 = load i32, ptr %3, align 450  %5 = icmp eq i32 %2, %451  br i1 %5, label %if.true, label %exit52 53if.true:54  %6 = shl i32 %4, 155  store i32 %6, ptr %3, align 456  br label %exit57 58exit:59  %7 = add nsw i32 %4, 160  store i32 %7, ptr %1, align 461  ret void62}63; CHECK-LABEL: test_GEP_across_BB:64; CHECK-NOT: lwzu65; CHECK: blr66 67; CHECK-UseAA-LABEL: test_GEP_across_BB(68; CHECK-UseAA: [[PTR0:%[a-zA-Z0-9]+]] = getelementptr69; CHECK-UseAA: getelementptr i8, ptr [[PTR0]], i64 52870; CHECK-UseAA: getelementptr i8, ptr [[PTR0]], i64 53271; CHECK-UseAA: if.true:72; CHECK-UseAA: {{%sunk[a-zA-Z0-9]+}} = getelementptr i8, ptr [[PTR0]], i64 53273; CHECK-UseAA: exit:74; CHECK-UseAA: {{%sunk[a-zA-Z0-9]+}} = getelementptr i8, ptr [[PTR0]], i64 52875 76%struct.S = type { float, double }77@struct_array = global [1024 x %struct.S] zeroinitializer, align 1678 79; The following two test cases check we can extract constant from indices of80; struct type.81; The constant offsets are from indices "i64 %idxprom" and "i32 1". As the82; alloca size of %struct.S is 16, and "i32 1" is the 2rd element whose field83; offset is 8, the total constant offset is (5 * 16 + 8) = 88.84define ptr @test-struct_1(i32 %i) {85entry:86  %add = add nsw i32 %i, 587  %idxprom = sext i32 %add to i6488  %p = getelementptr [1024 x %struct.S], ptr @struct_array, i64 0, i64 %idxprom, i32 189  ret ptr %p90}91; CHECK-UseAA-LABEL: @test-struct_1(92; CHECK-UseAA: getelementptr i8, ptr %{{[a-zA-Z0-9]+}}, i64 8893 94%struct3 = type { i64, i32 }95%struct2 = type { %struct3, i32 }96%struct1 = type { i64, %struct2 }97%struct0 = type { i32, i32, ptr, [100 x %struct1] }98 99; The constant offsets are from indices "i32 3", "i64 %arrayidx" and "i32 1".100; "i32 3" is the 4th element whose field offset is 16. The alloca size of101; %struct1 is 32. "i32 1" is the 2rd element whose field offset is 8. So the102; total constant offset is 16 + (-2 * 32) + 8 = -40103define ptr @test-struct_2(ptr %ptr, i64 %idx) {104entry:105  %arrayidx = add nsw i64 %idx, -2106  %ptr2 = getelementptr %struct0, ptr %ptr, i64 0, i32 3, i64 %arrayidx, i32 1107  ret ptr %ptr2108}109; CHECK-UseAA-LABEL: @test-struct_2(110; CHECK-UseAA: getelementptr i8, ptr %{{[a-zA-Z0-9]+}}, i64 -40111 112; Test that when a index is added from two constant, SeparateConstOffsetFromGEP113; pass does not generate incorrect result.114define void @test_const_add(ptr %in) {115  %inc = add nsw i32 2, 1116  %idxprom = sext i32 %inc to i64117  %arrayidx = getelementptr [3 x i32], ptr %in, i64 %idxprom, i64 2118  store i32 0, ptr %arrayidx, align 4119  ret void120}121; CHECK-LABEL: test_const_add:122; CHECK: li [[REG:[0-9]+]], 0123; CHECK: stw [[REG]], 44(3)124; CHECK: blr125 126