Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -1026,6 +1026,7 @@ } PipelineTuningOptions PTO; + PTO.LoopUnrolling = CodeGenOpts.UnrollLoops; // For historical reasons, loop interleaving is set to mirror setting for loop // unrolling. PTO.LoopInterleaving = CodeGenOpts.UnrollLoops; Index: test/CodeGen/loop-unroll.c =================================================================== --- /dev/null +++ test/CodeGen/loop-unroll.c @@ -0,0 +1,55 @@ +// RUN: %clang -target x86_64 -S -c -O1 -funroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL +// RUN: %clang -target x86_64 -S -c -O1 -fno-unroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-UNROLL +// RUN: %clang -target x86_64 -fexperimental-new-pass-manager -S -c -O1 -funroll-loops -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-UNROLL +// RUN: %clang -target x86_64 -fexperimental-new-pass-manager -S -c -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 + +#include + +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]); +}