brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 31f879c Raw
140 lines · plain
1; RUN: opt -loop-reduce -S < %s | FileCheck %s2 3target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"4target triple = "nvptx64-unknown-unknown"5 6; LSR used not to be able to generate a float* induction variable in7; these cases due to scalar evolution not propagating nsw from an8; instruction to the SCEV, preventing distributing sext into the9; corresponding addrec.10 11; Test this pattern:12;13;   for (int i = 0; i < numIterations; ++i)14;     sum += ptr[i + offset];15;16define float @testadd(ptr %input, i32 %offset, i32 %numIterations) {17; CHECK-LABEL: @testadd18; CHECK: sext i32 %offset to i6419; CHECK: loop:20; CHECK-DAG: phi ptr21; CHECK-DAG: phi i3222; CHECK-NOT: sext23 24entry:25  br label %loop26 27loop:28  %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]29  %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]30  %index32 = add nuw nsw i32 %i, %offset31  %index64 = sext i32 %index32 to i6432  %ptr = getelementptr inbounds float, ptr %input, i64 %index6433  %addend = load float, ptr %ptr, align 434  %nextsum = fadd float %sum, %addend35  %nexti = add nuw nsw i32 %i, 136  %exitcond = icmp eq i32 %nexti, %numIterations37  br i1 %exitcond, label %exit, label %loop38 39exit:40  ret float %nextsum41}42 43; Test this pattern:44;45;   for (int i = 0; i < numIterations; ++i)46;     sum += ptr[i - offset];47;48define float @testsub(ptr %input, i32 %offset, i32 %numIterations) {49; CHECK-LABEL: @testsub50; CHECK: sext i32 %offset to i6451; CHECK: loop:52; CHECK-DAG: phi ptr53; CHECK-DAG: phi i3254; CHECK-NOT: sext55 56entry:57  br label %loop58 59loop:60  %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]61  %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]62  %index32 = sub nuw nsw i32 %i, %offset63  %index64 = sext i32 %index32 to i6464  %ptr = getelementptr inbounds float, ptr %input, i64 %index6465  %addend = load float, ptr %ptr, align 466  %nextsum = fadd float %sum, %addend67  %nexti = add nuw nsw i32 %i, 168  %exitcond = icmp eq i32 %nexti, %numIterations69  br i1 %exitcond, label %exit, label %loop70 71exit:72  ret float %nextsum73}74 75; Test this pattern:76;77;   for (int i = 0; i < numIterations; ++i)78;     sum += ptr[i * stride];79;80define float @testmul(ptr %input, i32 %stride, i32 %numIterations) {81; CHECK-LABEL: @testmul82; CHECK: sext i32 %stride to i6483; CHECK: loop:84; CHECK-DAG: phi ptr85; CHECK-DAG: phi i3286; CHECK-NOT: sext87 88entry:89  br label %loop90 91loop:92  %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]93  %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]94  %index32 = mul nuw nsw i32 %i, %stride95  %index64 = sext i32 %index32 to i6496  %ptr = getelementptr inbounds float, ptr %input, i64 %index6497  %addend = load float, ptr %ptr, align 498  %nextsum = fadd float %sum, %addend99  %nexti = add nuw nsw i32 %i, 1100  %exitcond = icmp eq i32 %nexti, %numIterations101  br i1 %exitcond, label %exit, label %loop102 103exit:104  ret float %nextsum105}106 107; Test this pattern:108;109;   for (int i = 0; i < numIterations; ++i)110;     sum += ptr[3 * (i << 7)];111;112; The multiplication by 3 is to make the address calculation expensive113; enough to force the introduction of a pointer induction variable.114define float @testshl(ptr %input, i32 %numIterations) {115; CHECK-LABEL: @testshl116; CHECK: loop:117; CHECK-DAG: phi ptr118; CHECK-DAG: phi i32119; CHECK-NOT: sext120 121entry:122  br label %loop123 124loop:125  %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]126  %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]127  %index32 = shl nuw nsw i32 %i, 7128  %index32mul = mul nuw nsw i32 %index32, 3129  %index64 = sext i32 %index32mul to i64130  %ptr = getelementptr inbounds float, ptr %input, i64 %index64131  %addend = load float, ptr %ptr, align 4132  %nextsum = fadd float %sum, %addend133  %nexti = add nuw nsw i32 %i, 1134  %exitcond = icmp eq i32 %nexti, %numIterations135  br i1 %exitcond, label %exit, label %loop136 137exit:138  ret float %nextsum139}140