From 7f094f7f9d3e3c529afcfd553cee3b64419e72f2 Mon Sep 17 00:00:00 2001 From: Kirill Naumov Date: Tue, 2 Jun 2020 18:57:30 +0000 Subject: [PATCH] [InlineCost] PrinterPass prints constants to which instructions are simplified This patch enables printing of constants to see which instructions were constant-folded. Needed for tests and better visiual analysis of inliner's work. Reviewers: apilipenko, mtrofin, davidxl, fedor.sergeev Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D81024 --- llvm/lib/Analysis/InlineCost.cpp | 11 +++++++++++ llvm/test/Transforms/Inline/simplified_to.ll | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 llvm/test/Transforms/Inline/simplified_to.ll diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 5054427..f69c7f3 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -402,6 +402,12 @@ public: InlineResult analyze(); + Optional getSimplifiedValue(Instruction *I) { + if (SimplifiedValues.find(I) != SimplifiedValues.end()) + return SimplifiedValues[I]; + return None; + } + // Keep a bunch of stats about the cost savings found so we can print them // out when debugging. unsigned NumConstantArgs = 0; @@ -770,6 +776,11 @@ void InlineCostAnnotationWriter::emitInstructionAnnot(const Instruction *I, if (Record->hasThresholdChanged()) OS << ", threshold delta = " << Record->getThresholdDelta(); } + auto C = ICCA->getSimplifiedValue(const_cast(I)); + if (C) { + OS << ", simplified to "; + C.getValue()->print(OS, true); + } OS << "\n"; } diff --git a/llvm/test/Transforms/Inline/simplified_to.ll b/llvm/test/Transforms/Inline/simplified_to.ll new file mode 100644 index 0000000..92c84b5 --- /dev/null +++ b/llvm/test/Transforms/Inline/simplified_to.ll @@ -0,0 +1,15 @@ +; RUN: opt < %s -passes="print" 2>&1 | FileCheck %s + +; CHECK-LABEL: @test() +; CHECK: cost before = {{.*}}, cost after = {{.*}}, threshold before = {{.*}}, threshold after = {{.*}}, cost delta = {{.*}}, simplified to i1 false +; CHECK: %1 = icmp eq i32 4, 5 + +define i32 @test() { + %1 = icmp eq i32 4, 5 + ret i32 0 +} + +define void @main() { + %1 = call i32 @test() + ret void +} -- 2.7.4