Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

Commit 435bcea

Browse files
authored
[GISel] Add debug counter to force sdag fallback (#78257)
Add a debug counter that allows forcing an sdag fallback after a certain number of functions. The intended use-case is to bisect which function gets miscompiled by global isel using `-debug-counter=globalisel-count=N` (in cases where sdag doesn't also miscompile it, of course). The "falling back" debug line is printed unconditionally, because using `-debug-only` is usually too spammy for the intended purpose.
1 parent cde780c commit 435bcea

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@
3131
#include "llvm/Support/CodeGenCoverage.h"
3232
#include "llvm/Support/CommandLine.h"
3333
#include "llvm/Support/Debug.h"
34+
#include "llvm/Support/DebugCounter.h"
3435
#include "llvm/Target/TargetMachine.h"
3536

3637
#define DEBUG_TYPE "instruction-select"
3738

3839
using namespace llvm;
3940

41+
DEBUG_COUNTER(GlobalISelCounter, "globalisel",
42+
"Controls whether to select function with GlobalISel");
43+
4044
#ifdef LLVM_GISEL_COV_PREFIX
4145
static cl::opt<std::string>
4246
CoveragePrefix("gisel-coverage-prefix", cl::init(LLVM_GISEL_COV_PREFIX),
@@ -294,6 +298,13 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
294298
return false;
295299
}
296300
#endif
301+
302+
if (!DebugCounter::shouldExecute(GlobalISelCounter)) {
303+
dbgs() << "Falling back for function " << MF.getName() << "\n";
304+
MF.getProperties().set(MachineFunctionProperties::Property::FailedISel);
305+
return false;
306+
}
307+
297308
// Determine if there are any calls in this machine function. Ported from
298309
// SelectionDAG.
299310
MachineFrameInfo &MFI = MF.getFrameInfo();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -mtriple=aarch64-- -global-isel -global-isel-abort=0 -debug-counter=globalisel-count=1 %s -o - 2>/dev/null | FileCheck %s
3+
; RUN: llc -mtriple=aarch64-- -global-isel -global-isel-abort=0 -debug-counter=globalisel-count=1 %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=DEBUG
4+
5+
; REQUIRES: asserts
6+
7+
; DEBUG-NOT: Falling back for function test1
8+
; DEBUG: Falling back for function test2
9+
10+
define i32 @test1(i32 %x) {
11+
; CHECK-LABEL: test1:
12+
; CHECK: // %bb.0:
13+
; CHECK-NEXT: ret
14+
ret i32 %x
15+
}
16+
17+
define i32 @test2(i32 %x) {
18+
; CHECK-LABEL: test2:
19+
; CHECK: // %bb.0:
20+
; CHECK-NEXT: ret
21+
ret i32 %x
22+
}
23+
24+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
25+
; DEBUG: {{.*}}

0 commit comments

Comments
 (0)