[llvm] [DAGCombine] Add debug counter (PR #78259)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 03:37:42 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
Add a debug counter for DAGCombine. This can help with bisecting which DAG combine introduced a miscompile.
---
Full diff: https://github.com/llvm/llvm-project/pull/78259.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+7)
- (added) llvm/test/CodeGen/X86/dag-combine-counter.ll (+26)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/78259
More information about the llvm-commits
mailing list