diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2015-09-16 03:25:09 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2015-09-16 03:25:09 +0000 |
commit | fc314be0ec871771d2c7ecb31aa4c20a76328bfa (patch) | |
tree | 300189eb7955ffe034733ea969986548134b0986 /llvm | |
parent | 141dd91ac5d089c3ff3c8f8cd050c88c6ba50fc9 (diff) | |
download | bcm5719-llvm-fc314be0ec871771d2c7ecb31aa4c20a76328bfa.tar.gz bcm5719-llvm-fc314be0ec871771d2c7ecb31aa4c20a76328bfa.zip |
[Unroll] Fix a bug in UnrolledInstAnalyzer::visitLoad.
We only checked that a global is initialized with constants, which is
incorrect. We should be checking that GlobalVariable *is* a constant,
not just initialized with it.
llvm-svn: 247769
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Transforms/LoopUnroll/full-unroll-heuristics-2.ll | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index 6c510a5f9d9..0e4462618aa 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -415,7 +415,7 @@ private: auto *GV = dyn_cast<GlobalVariable>(AddressIt->second.Base); // We're only interested in loads that can be completely folded to a // constant. - if (!GV || !GV->hasInitializer()) + if (!GV || !GV->hasInitializer() || !GV->isConstant()) return false; ConstantDataSequential *CDS = diff --git a/llvm/test/Transforms/LoopUnroll/full-unroll-heuristics-2.ll b/llvm/test/Transforms/LoopUnroll/full-unroll-heuristics-2.ll new file mode 100644 index 00000000000..cd687834fdf --- /dev/null +++ b/llvm/test/Transforms/LoopUnroll/full-unroll-heuristics-2.ll @@ -0,0 +1,29 @@ +; RUN: opt < %s -S -loop-unroll -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=10 -unroll-percent-dynamic-cost-saved-threshold=50 -unroll-dynamic-cost-savings-discount=90 | FileCheck %s +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" + +; Though @unknown_global is initialized with constant values, we can't consider +; it as a constant, so we shouldn't unroll the loop. +; CHECK: %array_const_idx = getelementptr inbounds [9 x i32], [9 x i32]* @unknown_global, i64 0, i64 %iv +@unknown_global = internal unnamed_addr global [9 x i32] [i32 0, i32 -1, i32 0, i32 -1, i32 5, i32 -1, i32 0, i32 -1, i32 0], align 16 + +define i32 @foo(i32* noalias nocapture readonly %src) { +entry: + br label %loop + +loop: ; preds = %loop, %entry + %iv = phi i64 [ 0, %entry ], [ %inc, %loop ] + %r = phi i32 [ 0, %entry ], [ %add, %loop ] + %arrayidx = getelementptr inbounds i32, i32* %src, i64 %iv + %src_element = load i32, i32* %arrayidx, align 4 + %array_const_idx = getelementptr inbounds [9 x i32], [9 x i32]* @unknown_global, i64 0, i64 %iv + %const_array_element = load i32, i32* %array_const_idx, align 4 + %mul = mul nsw i32 %src_element, %const_array_element + %add = add nsw i32 %mul, %r + %inc = add nuw nsw i64 %iv, 1 + %exitcond86.i = icmp eq i64 %inc, 9 + br i1 %exitcond86.i, label %loop.end, label %loop + +loop.end: ; preds = %loop + %r.lcssa = phi i32 [ %r, %loop ] + ret i32 %r.lcssa +} |