[PATCH] D81024: InlineCostAnnotationPrinterPass - print constants to which instructions are simplified

Kirill Naumov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 17 06:59:02 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG52b0db22f8cf: [InlineCost] PrinterPass prints constants to which instructions are simplified (authored by knaumov).

Changed prior to commit:
  https://reviews.llvm.org/D81024?vs=267945&id=271362#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81024/new/

https://reviews.llvm.org/D81024

Files:
  llvm/lib/Analysis/InlineCost.cpp
  llvm/test/Transforms/Inline/simplified_to.ll


Index: llvm/test/Transforms/Inline/simplified_to.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/simplified_to.ll
@@ -0,0 +1,15 @@
+; RUN: opt < %s -passes="print<inline-cost>" 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
+}
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -402,6 +402,12 @@
 
   InlineResult analyze();
 
+  Optional<Constant*> 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;
@@ -766,6 +772,11 @@
     if (Record->hasThresholdChanged())
       OS << ", threshold delta = " << Record->getThresholdDelta();
   }
+  auto C = ICCA->getSimplifiedValue(const_cast<Instruction *>(I));
+  if (C) {
+    OS << ", simplified to ";
+    C.getValue()->print(OS, true);
+  }
   OS << "\n";
 }
 
@@ -2545,4 +2556,4 @@
     }
   }
   return PreservedAnalyses::all();
-}
\ No newline at end of file
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81024.271362.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200617/e9bf09f6/attachment.bin>


More information about the llvm-commits mailing list