Skip to content

Commit ce3c3cb

Browse files
committed
[llvm-reduce] Check if reduction fails/is redundant before invoking oracle
So we don't over count the number of chunks and do unnecessary work reducing more chunks than exist. This lowers some random reduction I tested with locally from 250s to 232s. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D136127
1 parent d1dc58c commit ce3c3cb

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2>&1 | FileCheck %s --check-prefix=CHECK-LOG
2+
; RUN: FileCheck --check-prefixes=CHECK-FINAL --input-file=%t %s
3+
4+
; CHECK-INTERESTINGNESS: ret i32
5+
; CHECK-FINAL: ret i32 0
6+
7+
; Test that we don't invoke the oracle more than necessary (e.g. check the
8+
; oracle then perform some failable/redundant reduction, as opposed to check if
9+
; a reduction will fail/be redundant before invoking the oracle). This prevents
10+
; overestimation of the number of possible reductions and the number of times we
11+
; attempt to reduce.
12+
13+
; IR passes
14+
; CHECK-LOG: Saved new best reduction
15+
; Module data
16+
; CHECK-LOG: Saved new best reduction
17+
; SimplifyCFG
18+
; CHECK-LOG: Saved new best reduction
19+
; CHECK-LOG-NOT: Saved new best reduction
20+
21+
define i32 @f() {
22+
ret i32 0
23+
}

llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ static void replaceOpcodesInModule(Oracle &O, Module &Mod) {
8787
for (Function &F : Mod) {
8888
for (BasicBlock &BB : F)
8989
for (Instruction &I : make_early_inc_range(BB)) {
90-
if (O.shouldKeep())
91-
continue;
9290

9391
Instruction *Replacement =
9492
dyn_cast_or_null<Instruction>(reduceInstruction(Mod, I));
9593
if (Replacement && Replacement != &I) {
94+
if (O.shouldKeep())
95+
continue;
96+
9697
if (isa<FPMathOperator>(Replacement))
9798
Replacement->copyFastMathFlags(&I);
9899

llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ extractOperandsFromModule(Oracle &O, Module &Program,
3434
}
3535

3636
for (auto &Op : I.operands()) {
37-
if (!O.shouldKeep()) {
38-
if (Value *Reduced = ReduceValue(Op))
37+
if (Value *Reduced = ReduceValue(Op)) {
38+
if (!O.shouldKeep())
3939
Op.set(Reduced);
4040
}
4141
}

llvm/tools/llvm-reduce/deltas/SimplifyInstructions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ static void extractInstrFromModule(Oracle &O, Module &Program) {
2828
for (auto &F : Program) {
2929
for (auto &BB : F) {
3030
for (auto &Inst : BB) {
31-
if (O.shouldKeep())
32-
continue;
3331

3432
SimplifyQuery Q(DL, &Inst);
3533
if (Value *Simplified = simplifyInstruction(&Inst, Q)) {
34+
if (O.shouldKeep())
35+
continue;
3636
Inst.replaceAllUsesWith(Simplified);
3737
InstToDelete.push_back(&Inst);
3838
}

0 commit comments

Comments
 (0)