From 15b589712ea072d47dffc23bbfb266e7c540f7e0 Mon Sep 17 00:00:00 2001 From: Camsyn Date: Mon, 27 Oct 2025 21:11:29 +0800 Subject: [PATCH 1/3] Reformat PT_Switch annotation to make it as legal comments --- llvm/lib/Transforms/Utils/PredicateInfo.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp index 978d5a25a57c8..4f0f756ecc3ca 100644 --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/IR/AssemblyAnnotationWriter.h" #include "llvm/IR/Dominators.h" @@ -25,6 +26,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/DebugCounter.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/raw_ostream.h" #define DEBUG_TYPE "predicateinfo" using namespace llvm; using namespace PatternMatch; @@ -812,11 +814,23 @@ class PredicateInfoAnnotatedWriter : public AssemblyAnnotationWriter { OS << "]"; } else if (const auto *PS = dyn_cast(PI)) { OS << "; switch predicate info { CaseValue: " << *PS->CaseValue - << " Switch:" << *PS->Switch << " Edge: ["; + << " Edge: ["; PS->From->printAsOperand(OS); OS << ","; PS->To->printAsOperand(OS); - OS << "]"; + OS << "] Switch:\n"; + // A switch might cross > 1 lines, we should add the comment prefix ';' + // for each line + std::string SwitchStr; + { + llvm::raw_string_ostream SwitchOS(SwitchStr); + PS->Switch->print(SwitchOS); + } + SmallVector Lines; + StringRef(SwitchStr).split(Lines, '\n'); + for (const auto &Line : Lines) + OS << "; " << Line << "\n"; + OS << "; "; } else if (const auto *PA = dyn_cast(PI)) { OS << "; assume predicate info {" << " Comparison:" << *PA->Condition; From ac779d741dc82fbfb92493473dae4cf72c60c286 Mon Sep 17 00:00:00 2001 From: Camsyn Date: Mon, 27 Oct 2025 21:25:31 +0800 Subject: [PATCH 2/3] Regenerate the test --- .../Transforms/Util/PredicateInfo/condprop.ll | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/llvm/test/Transforms/Util/PredicateInfo/condprop.ll b/llvm/test/Transforms/Util/PredicateInfo/condprop.ll index 0235732b95a83..256d0d908ec1e 100644 --- a/llvm/test/Transforms/Util/PredicateInfo/condprop.ll +++ b/llvm/test/Transforms/Util/PredicateInfo/condprop.ll @@ -133,19 +133,13 @@ define void @test4(i1 %b, i32 %x) { ; CHECK-LABEL: @test4( ; CHECK-NEXT: br i1 [[B:%.*]], label [[SW:%.*]], label [[CASE3:%.*]] ; CHECK: sw: -; CHECK: i32 0, label [[CASE0:%.*]] -; CHECK-NEXT: i32 1, label [[CASE1:%.*]] -; CHECK-NEXT: i32 2, label [[CASE0]] -; CHECK-NEXT: i32 3, label [[CASE3]] -; CHECK-NEXT: i32 4, label [[DEFAULT:%.*]] -; CHECK-NEXT: ] Edge: [label [[SW]],label %case1], RenamedOp: [[X:%.*]] } -; CHECK-NEXT: [[X_0:%.*]] = bitcast i32 [[X]] to i32 -; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT]] [ -; CHECK-NEXT: i32 0, label [[CASE0]] -; CHECK-NEXT: i32 1, label [[CASE1]] -; CHECK-NEXT: i32 2, label [[CASE0]] -; CHECK-NEXT: i32 3, label [[CASE3]] -; CHECK-NEXT: i32 4, label [[DEFAULT]] +; CHECK: [[X_0:%.*]] = bitcast i32 [[X:%.*]] to i32 +; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT:%.*]] [ +; CHECK-NEXT: i32 0, label [[CASE0:%.*]] +; CHECK-NEXT: i32 1, label [[CASE1:%.*]] +; CHECK-NEXT: i32 2, label [[CASE0]] +; CHECK-NEXT: i32 3, label [[CASE3]] +; CHECK-NEXT: i32 4, label [[DEFAULT]] ; CHECK-NEXT: ] ; CHECK: default: ; CHECK-NEXT: call void @bar(i32 [[X]]) From b564af6b72a23cb06b701f1b97e846036fdd7f22 Mon Sep 17 00:00:00 2001 From: Camsyn Date: Mon, 27 Oct 2025 22:55:50 +0800 Subject: [PATCH 3/3] Remove switch printing following review comments --- llvm/lib/Transforms/Utils/PredicateInfo.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp index 4f0f756ecc3ca..2faaa19f91a1b 100644 --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -14,7 +14,6 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/IR/AssemblyAnnotationWriter.h" #include "llvm/IR/Dominators.h" @@ -26,7 +25,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/DebugCounter.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/Support/raw_ostream.h" #define DEBUG_TYPE "predicateinfo" using namespace llvm; using namespace PatternMatch; @@ -818,19 +816,7 @@ class PredicateInfoAnnotatedWriter : public AssemblyAnnotationWriter { PS->From->printAsOperand(OS); OS << ","; PS->To->printAsOperand(OS); - OS << "] Switch:\n"; - // A switch might cross > 1 lines, we should add the comment prefix ';' - // for each line - std::string SwitchStr; - { - llvm::raw_string_ostream SwitchOS(SwitchStr); - PS->Switch->print(SwitchOS); - } - SmallVector Lines; - StringRef(SwitchStr).split(Lines, '\n'); - for (const auto &Line : Lines) - OS << "; " << Line << "\n"; - OS << "; "; + OS << "]"; } else if (const auto *PA = dyn_cast(PI)) { OS << "; assume predicate info {" << " Comparison:" << *PA->Condition;