From: Alina Sbirlea Date: Fri, 24 May 2019 17:40:52 +0000 (+0000) Subject: [NewPassManager] Add tuning option: LoopUnrolling [clang-change] X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e64402733cde0c4f5a60423775fd95457b01def7;p=clang [NewPassManager] Add tuning option: LoopUnrolling [clang-change] Summary: Use CodeGenOpts's setting for loop unrolling. [to be coupled with D61618] Reviewers: chandlerc Subscribers: jlebar, dmgreen, cfe-commits, llvm-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61620 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361653 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 1dbeec1c17..c5e56c7a06 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -1051,6 +1051,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( } PipelineTuningOptions PTO; + PTO.LoopUnrolling = CodeGenOpts.UnrollLoops; // For historical reasons, loop interleaving is set to mirror setting for loop // unrolling. PTO.LoopInterleaving = CodeGenOpts.UnrollLoops; diff --git a/test/CodeGen/loop-unroll.c b/test/CodeGen/loop-unroll.c new file mode 100644 index 0000000000..c37411fa05 --- /dev/null +++ b/test/CodeGen/loop-unroll.c @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64 -target-cpu x86-64 -S -O1 -funroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL +// RUN: %clang_cc1 -triple x86_64 -target-cpu x86-64 -S -O1 -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-UNROLL +// RUN: %clang_cc1 -triple x86_64 -target-cpu x86-64 -fexperimental-new-pass-manager -S -O1 -funroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL +// RUN: %clang_cc1 -triple x86_64 -target-cpu x86-64 -fexperimental-new-pass-manager -S -O1 -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-UNROLL + +// CHECK-ENABLE-UNROLL-LABEL: @for_test() +// CHECK-ENABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]] +// CHECK-ENABLE-UNROLL: [[FORBODY]]: +// CHECK-ENABLE-UNROLL: store +// CHECK-ENABLE-UNROLL: store +// CHECK-ENABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label %[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]] +// CHECK-ENABLE-UNROLL: [[FORBODY5]]: +// CHECK-ENABLE-UNROLL: fmul +// CHECK-ENABLE-UNROLL: fadd +// CHECK-ENABLE-UNROLL: store +// CHECK-ENABLE-UNROLL: fmul +// CHECK-ENABLE-UNROLL: fadd +// CHECK-ENABLE-UNROLL: store +// CHECK-ENABLE-UNROLL: fmul +// CHECK-ENABLE-UNROLL: fadd +// CHECK-ENABLE-UNROLL: store + +// CHECK-DISABLE-UNROLL-LABEL: @for_test() +// CHECK-DISABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]] +// CHECK-DISABLE-UNROLL: [[FORBODY]]: +// CHECK-DISABLE-UNROLL: store +// CHECK-DISABLE-UNROLL-NOT: store +// CHECK-DISABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label %[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]] +// CHECK-DISABLE-UNROLL: [[FORBODY5]]: +// CHECK-DISABLE-UNROLL: fmul +// CHECK-DISABLE-UNROLL: fadd +// CHECK-DISABLE-UNROLL: store +// CHECK-DISABLE-UNROLL: fmul +// CHECK-DISABLE-UNROLL: fadd +// CHECK-DISABLE-UNROLL: store +// CHECK-DISABLE-UNROLL-NOT: fmul +// CHECK-DISABLE-UNROLL-NOT: fadd +// CHECK-DISABLE-UNROLL-NOT: store + +int printf(const char * restrict format, ...); + +void for_test() { + double A[1000], B[1000]; + int L = 500; + for (int i = 0; i < L; i++) { + A[i] = i; + } + for (int i = 0; i < L; i++) { + B[i] = A[i]*5; + B[i]++; + A[i] *= 7; + A[i]++; + } + printf("%lf %lf\n", A[0], B[0]); +}