Skip to content

Commit 5a13188

Browse files
author
Sjoerd Meijer
committed
Revert "[HardwareLoops] Optimisation remarks"
while I investigate the PPC build bot failures. This reverts commit ad76375. llvm-svn: 374992
1 parent b150494 commit 5a13188

File tree

4 files changed

+25
-97
lines changed

4 files changed

+25
-97
lines changed

llvm/lib/CodeGen/HardwareLoops.cpp

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "llvm/ADT/Statistic.h"
2222
#include "llvm/Analysis/AssumptionCache.h"
2323
#include "llvm/Analysis/LoopInfo.h"
24-
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
2524
#include "llvm/Analysis/ScalarEvolution.h"
2625
#include "llvm/Analysis/ScalarEvolutionExpander.h"
2726
#include "llvm/Analysis/TargetTransformInfo.h"
@@ -76,44 +75,8 @@ ForceGuardLoopEntry(
7675

7776
STATISTIC(NumHWLoops, "Number of loops converted to hardware loops");
7877

79-
#ifndef NDEBUG
80-
static void debugHWLoopFailure(const StringRef DebugMsg,
81-
Instruction *I) {
82-
dbgs() << "HWLoops: " << DebugMsg;
83-
if (I)
84-
dbgs() << ' ' << *I;
85-
else
86-
dbgs() << '.';
87-
dbgs() << '\n';
88-
}
89-
#endif
90-
91-
static OptimizationRemarkAnalysis
92-
createHWLoopAnalysis(StringRef RemarkName, Loop *L, Instruction *I) {
93-
Value *CodeRegion = L->getHeader();
94-
DebugLoc DL = L->getStartLoc();
95-
96-
if (I) {
97-
CodeRegion = I->getParent();
98-
// If there is no debug location attached to the instruction, revert back to
99-
// using the loop's.
100-
if (I->getDebugLoc())
101-
DL = I->getDebugLoc();
102-
}
103-
104-
OptimizationRemarkAnalysis R(DEBUG_TYPE, RemarkName, DL, CodeRegion);
105-
R << "hardware-loop not created: ";
106-
return R;
107-
}
108-
10978
namespace {
11079

111-
void reportHWLoopFailure(const StringRef Msg, const StringRef ORETag,
112-
OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I = nullptr) {
113-
LLVM_DEBUG(debugHWLoopFailure(Msg, I));
114-
ORE->emit(createHWLoopAnalysis(ORETag, TheLoop, I) << Msg);
115-
}
116-
11780
using TTI = TargetTransformInfo;
11881

11982
class HardwareLoops : public FunctionPass {
@@ -134,7 +97,6 @@ namespace {
13497
AU.addRequired<ScalarEvolutionWrapperPass>();
13598
AU.addRequired<AssumptionCacheTracker>();
13699
AU.addRequired<TargetTransformInfoWrapperPass>();
137-
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
138100
}
139101

140102
// Try to convert the given Loop into a hardware loop.
@@ -148,7 +110,6 @@ namespace {
148110
ScalarEvolution *SE = nullptr;
149111
LoopInfo *LI = nullptr;
150112
const DataLayout *DL = nullptr;
151-
OptimizationRemarkEmitter *ORE = nullptr;
152113
const TargetTransformInfo *TTI = nullptr;
153114
DominatorTree *DT = nullptr;
154115
bool PreserveLCSSA = false;
@@ -182,9 +143,8 @@ namespace {
182143

183144
public:
184145
HardwareLoop(HardwareLoopInfo &Info, ScalarEvolution &SE,
185-
const DataLayout &DL,
186-
OptimizationRemarkEmitter *ORE) :
187-
SE(SE), DL(DL), ORE(ORE), L(Info.L), M(L->getHeader()->getModule()),
146+
const DataLayout &DL) :
147+
SE(SE), DL(DL), L(Info.L), M(L->getHeader()->getModule()),
188148
ExitCount(Info.ExitCount),
189149
CountType(Info.CountType),
190150
ExitBranch(Info.ExitBranch),
@@ -197,7 +157,6 @@ namespace {
197157
private:
198158
ScalarEvolution &SE;
199159
const DataLayout &DL;
200-
OptimizationRemarkEmitter *ORE = nullptr;
201160
Loop *L = nullptr;
202161
Module *M = nullptr;
203162
const SCEV *ExitCount = nullptr;
@@ -223,7 +182,6 @@ bool HardwareLoops::runOnFunction(Function &F) {
223182
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
224183
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
225184
DL = &F.getParent()->getDataLayout();
226-
ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
227185
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
228186
LibInfo = TLIP ? &TLIP->getTLI(F) : nullptr;
229187
PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
@@ -243,39 +201,31 @@ bool HardwareLoops::runOnFunction(Function &F) {
243201
// converted and the parent loop doesn't support containing a hardware loop.
244202
bool HardwareLoops::TryConvertLoop(Loop *L) {
245203
// Process nested loops first.
246-
for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) {
247-
if (TryConvertLoop(*I)) {
248-
reportHWLoopFailure("nested hardware-loops not supported", "HWLoopNested",
249-
ORE, L);
204+
for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
205+
if (TryConvertLoop(*I))
250206
return true; // Stop search.
251-
}
252-
}
253207

254208
HardwareLoopInfo HWLoopInfo(L);
255-
if (!HWLoopInfo.canAnalyze(*LI)) {
256-
reportHWLoopFailure("cannot analyze loop, irreducible control flow",
257-
"HWLoopCannotAnalyze", ORE, L);
209+
if (!HWLoopInfo.canAnalyze(*LI))
258210
return false;
259-
}
260211

261-
if (!ForceHardwareLoops &&
262-
!TTI->isHardwareLoopProfitable(L, *SE, *AC, LibInfo, HWLoopInfo)) {
263-
reportHWLoopFailure("it's not profitable to create a hardware-loop",
264-
"HWLoopNotProfitable", ORE, L);
265-
return false;
266-
}
212+
if (TTI->isHardwareLoopProfitable(L, *SE, *AC, LibInfo, HWLoopInfo) ||
213+
ForceHardwareLoops) {
214+
215+
// Allow overriding of the counter width and loop decrement value.
216+
if (CounterBitWidth.getNumOccurrences())
217+
HWLoopInfo.CountType =
218+
IntegerType::get(M->getContext(), CounterBitWidth);
267219

268-
// Allow overriding of the counter width and loop decrement value.
269-
if (CounterBitWidth.getNumOccurrences())
270-
HWLoopInfo.CountType =
271-
IntegerType::get(M->getContext(), CounterBitWidth);
220+
if (LoopDecrement.getNumOccurrences())
221+
HWLoopInfo.LoopDecrement =
222+
ConstantInt::get(HWLoopInfo.CountType, LoopDecrement);
272223

273-
if (LoopDecrement.getNumOccurrences())
274-
HWLoopInfo.LoopDecrement =
275-
ConstantInt::get(HWLoopInfo.CountType, LoopDecrement);
224+
MadeChange |= TryConvertLoop(HWLoopInfo);
225+
return MadeChange && (!HWLoopInfo.IsNestingLegal && !ForceNestedLoop);
226+
}
276227

277-
MadeChange |= TryConvertLoop(HWLoopInfo);
278-
return MadeChange && (!HWLoopInfo.IsNestingLegal && !ForceNestedLoop);
228+
return false;
279229
}
280230

281231
bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
@@ -284,13 +234,8 @@ bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
284234
LLVM_DEBUG(dbgs() << "HWLoops: Try to convert profitable loop: " << *L);
285235

286236
if (!HWLoopInfo.isHardwareLoopCandidate(*SE, *LI, *DT, ForceNestedLoop,
287-
ForceHardwareLoopPHI)) {
288-
// TODO: there can be many reasons a loop is not considered a
289-
// candidate, so we should let isHardwareLoopCandidate fill in the
290-
// reason and then report a better message here.
291-
reportHWLoopFailure("loop is not a candidate", "HWLoopNoCandidate", ORE, L);
237+
ForceHardwareLoopPHI))
292238
return false;
293-
}
294239

295240
assert(
296241
(HWLoopInfo.ExitBlock && HWLoopInfo.ExitBranch && HWLoopInfo.ExitCount) &&
@@ -304,21 +249,18 @@ bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
304249
if (!Preheader)
305250
return false;
306251

307-
HardwareLoop HWLoop(HWLoopInfo, *SE, *DL, ORE);
252+
HardwareLoop HWLoop(HWLoopInfo, *SE, *DL);
308253
HWLoop.Create();
309254
++NumHWLoops;
310255
return true;
311256
}
312257

313258
void HardwareLoop::Create() {
314259
LLVM_DEBUG(dbgs() << "HWLoops: Converting loop..\n");
315-
260+
316261
Value *LoopCountInit = InitLoopCount();
317-
if (!LoopCountInit) {
318-
reportHWLoopFailure("could not safely create a loop count expression",
319-
"HWLoopNotSafe", ORE, L);
262+
if (!LoopCountInit)
320263
return;
321-
}
322264

323265
InsertIterationSetup(LoopCountInit);
324266

llvm/test/CodeGen/ARM/O3-pipeline.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
; CHECK-NEXT: Dominator Tree Construction
5353
; CHECK-NEXT: Natural Loop Information
5454
; CHECK-NEXT: Scalar Evolution Analysis
55-
; CHECK-NEXT: Lazy Branch Probability Analysis
56-
; CHECK-NEXT: Lazy Block Frequency Analysis
57-
; CHECK-NEXT: Optimization Remark Emitter
5855
; CHECK-NEXT: Hardware Loop Insertion
5956
; CHECK-NEXT: Scalar Evolution Analysis
6057
; CHECK-NEXT: Loop Pass Manager

llvm/test/Transforms/HardwareLoops/ARM/structure.ll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
; RUN: opt -mtriple=thumbv8.1m.main-arm-none-eabi -hardware-loops %s -S -o - | FileCheck %s
2-
; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi %s -o - -pass-remarks-analysis=hardware-loops 2>&1 | FileCheck %s --check-prefix=CHECK-LLC
2+
; RUN: llc -mtriple=thumbv8.1m.main-arm-none-eabi %s -o - | FileCheck %s --check-prefix=CHECK-LLC
33
; RUN: opt -mtriple=thumbv8.1m.main -loop-unroll -unroll-remainder=false -S < %s | llc -mtriple=thumbv8.1m.main | FileCheck %s --check-prefix=CHECK-UNROLL
44

5-
; CHECK-LLC: remark: <unknown>:0:0: hardware-loop not created: it's not profitable to create a hardware-loop
65
; CHECK-LABEL: early_exit
76
; CHECK-NOT: llvm.set.loop.iterations
87
; CHECK-NOT: llvm.loop.decrement
@@ -47,7 +46,6 @@ do.end:
4746
; CHECK-NOT: [[LOOP_DEC1:%[^ ]+]] = call i1 @llvm.loop.decrement.i32(i32 1)
4847
; CHECK-NOT: br i1 [[LOOP_DEC1]], label %while.cond1.preheader.us, label %while.end7
4948

50-
; CHECK-LLC: remark: <unknown>:0:0: hardware-loop not created: nested hardware-loops not supported
5149
; CHECK-LLC: nested:
5250
; CHECK-LLC-NOT: mov lr, r1
5351
; CHECK-LLC: dls lr, r1
@@ -178,9 +176,6 @@ while.end7:
178176
ret void
179177
}
180178

181-
182-
; CHECK-LLC: remark: <unknown>:0:0: hardware-loop not created: loop is not a candidate
183-
; CHECK-LLC: remark: <unknown>:0:0: hardware-loop not created: nested hardware-loops not supported
184179
; CHECK-LABEL: not_rotated
185180
; CHECK-NOT: call void @llvm.set.loop.iterations
186181
; CHECK-NOT: call i32 @llvm.loop.decrement.i32

llvm/test/Transforms/HardwareLoops/unconditional-latch.ll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
; RUN: opt -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -hardware-loops -S %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ALLOW
22
; RUN: opt -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -hardware-loops -force-hardware-loop-guard=true -S %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ALLOW
3-
;
4-
; RUN: opt -force-hardware-loops=true -hardware-loop-decrement=1 \
5-
; RUN: -hardware-loop-counter-bitwidth=32 -force-hardware-loop-phi=true \
6-
; RUN: -hardware-loops -S -pass-remarks-analysis=hardware-loops %s -o - \
7-
; RUN: 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-LATCH
8-
9-
; CHECK-LATCH: remark: <unknown>:0:0: hardware-loop not created: loop is not a candidate
3+
; RUN: opt -force-hardware-loops=true -hardware-loop-decrement=1 -hardware-loop-counter-bitwidth=32 -force-hardware-loop-phi=true -hardware-loops -S %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-LATCH
104

115
; CHECK-LABEL: not_rotated
126
; CHECK-LATCH-NOT: call void @llvm.set.loop.iterations

0 commit comments

Comments
 (0)