[llvm] [DAGCombine] Add debug counter (PR #78259)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 03:37:12 PST 2024


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/78259

Add a debug counter for DAGCombine. This can help with bisecting which DAG combine introduced a miscompile.

>From 3c200d1a9b02ca1fb54405ed7ba408698116a3cb Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 16 Jan 2024 12:34:44 +0100
Subject: [PATCH] [DAGCombine] Add debug counter

Add a debug counter for DAGCombine. This can help with bisecting
which DAG combine introduced a miscompile.
---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp |  7 +++++
 llvm/test/CodeGen/X86/dag-combine-counter.ll  | 26 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 llvm/test/CodeGen/X86/dag-combine-counter.ll

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index ecdf9ab9e989f0..9365e655445775 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -58,6 +58,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/KnownBits.h"
 #include "llvm/Support/MathExtras.h"
@@ -87,6 +88,9 @@ STATISTIC(LdStFP2Int      , "Number of fp load/store pairs transformed to int");
 STATISTIC(SlicedLoads, "Number of load sliced");
 STATISTIC(NumFPLogicOpsConv, "Number of logic ops converted to fp ops");
 
+DEBUG_COUNTER(DAGCombineCounter, "dagcombine",
+              "Controls whether a DAG combine is performed for a node");
+
 static cl::opt<bool>
 CombinerGlobalAA("combiner-global-alias-analysis", cl::Hidden,
                  cl::desc("Enable DAG combiner's use of IR alias analysis"));
@@ -2076,6 +2080,9 @@ SDValue DAGCombiner::visit(SDNode *N) {
 }
 
 SDValue DAGCombiner::combine(SDNode *N) {
+  if (!DebugCounter::shouldExecute(DAGCombineCounter))
+    return SDValue();
+
   SDValue RV;
   if (!DisableGenericCombines)
     RV = visit(N);
diff --git a/llvm/test/CodeGen/X86/dag-combine-counter.ll b/llvm/test/CodeGen/X86/dag-combine-counter.ll
new file mode 100644
index 00000000000000..8568db8d840a4d
--- /dev/null
+++ b/llvm/test/CodeGen/X86/dag-combine-counter.ll
@@ -0,0 +1,26 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc -mtriple=x86_64-- -debug-counter=dagcombine-count=6 < %s | FileCheck %s
+
+; REQUIRES: asserts
+
+define i32 @test(i32 %x) {
+; CHECK-LABEL: test:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    movl %edi, %eax
+; CHECK-NEXT:    retq
+  %y = add i32 %x, 1
+  %z = sub i32 %y, 1
+  ret i32 %z
+}
+
+define i32 @test2(i32 %x) {
+; CHECK-LABEL: test2:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    # kill: def $edi killed $edi def $rdi
+; CHECK-NEXT:    leal 1(%rdi), %eax
+; CHECK-NEXT:    subl $1, %eax
+; CHECK-NEXT:    retq
+  %y = add i32 %x, 1
+  %z = sub i32 %y, 1
+  ret i32 %z
+}



More information about the llvm-commits mailing list