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

Commit cde780c

Browse files
authored
[DAGCombine] Add debug counter (#78259)
Add a debug counter for DAGCombine. This can help with bisecting which DAG combine introduced a miscompile.
1 parent 5f57ad8 commit cde780c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/Support/CommandLine.h"
5959
#include "llvm/Support/Compiler.h"
6060
#include "llvm/Support/Debug.h"
61+
#include "llvm/Support/DebugCounter.h"
6162
#include "llvm/Support/ErrorHandling.h"
6263
#include "llvm/Support/KnownBits.h"
6364
#include "llvm/Support/MathExtras.h"
@@ -87,6 +88,9 @@ STATISTIC(LdStFP2Int , "Number of fp load/store pairs transformed to int");
8788
STATISTIC(SlicedLoads, "Number of load sliced");
8889
STATISTIC(NumFPLogicOpsConv, "Number of logic ops converted to fp ops");
8990

91+
DEBUG_COUNTER(DAGCombineCounter, "dagcombine",
92+
"Controls whether a DAG combine is performed for a node");
93+
9094
static cl::opt<bool>
9195
CombinerGlobalAA("combiner-global-alias-analysis", cl::Hidden,
9296
cl::desc("Enable DAG combiner's use of IR alias analysis"));
@@ -2076,6 +2080,9 @@ SDValue DAGCombiner::visit(SDNode *N) {
20762080
}
20772081

20782082
SDValue DAGCombiner::combine(SDNode *N) {
2083+
if (!DebugCounter::shouldExecute(DAGCombineCounter))
2084+
return SDValue();
2085+
20792086
SDValue RV;
20802087
if (!DisableGenericCombines)
20812088
RV = visit(N);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -mtriple=x86_64-- -debug-counter=dagcombine-count=6 < %s | FileCheck %s
3+
4+
; REQUIRES: asserts
5+
6+
define i32 @test(i32 %x) {
7+
; CHECK-LABEL: test:
8+
; CHECK: # %bb.0:
9+
; CHECK-NEXT: movl %edi, %eax
10+
; CHECK-NEXT: retq
11+
%y = add i32 %x, 1
12+
%z = sub i32 %y, 1
13+
ret i32 %z
14+
}
15+
16+
define i32 @test2(i32 %x) {
17+
; CHECK-LABEL: test2:
18+
; CHECK: # %bb.0:
19+
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
20+
; CHECK-NEXT: leal 1(%rdi), %eax
21+
; CHECK-NEXT: subl $1, %eax
22+
; CHECK-NEXT: retq
23+
%y = add i32 %x, 1
24+
%z = sub i32 %y, 1
25+
ret i32 %z
26+
}

0 commit comments

Comments
 (0)