[llvm] 475abe1 - [Attributor] Make use of analysis in the MustBeExecutedExplorer
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 17:10:48 PDT 2020
Author: Shinji Okumura
Date: 2020-04-04T19:08:44-05:00
New Revision: 475abe14a59f43a976f479091798e879cfc739d0
URL: https://github.com/llvm/llvm-project/commit/475abe14a59f43a976f479091798e879cfc739d0
DIFF: https://github.com/llvm/llvm-project/commit/475abe14a59f43a976f479091798e879cfc739d0.diff
LOG: [Attributor] Make use of analysis in the MustBeExecutedExplorer
This commit was made to settle [[ https://github.com/llvm/llvm-project/issues/175 | this issue on GitHub ]].
I added analysis getters for LoopInfo, DominatorTree, and
PostDominatorTree. And I added a test to show an improvement of the
deduction of `dereferenceable` attribute.
Reviewed By: jdoerfert, uenoku
Differential Revision: https://reviews.llvm.org/D76378
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/test/Transforms/Attributor/dereferenceable-2.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index b0c7db2822c9..1165c68a37e9 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -107,6 +107,7 @@
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/MustExecute.h"
+#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CallSite.h"
@@ -566,8 +567,19 @@ struct InformationCache {
InformationCache(const Module &M, AnalysisGetter &AG,
SetVector<Function *> *CGSCC)
: DL(M.getDataLayout()),
- Explorer(/* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
- /* ExploreCFGBackward */ true),
+ Explorer(
+ /* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
+ /* ExploreCFGBackward */ true,
+ /* LIGetter */
+ [&](const Function &F) { return AG.getAnalysis<LoopAnalysis>(F); },
+ /* DTGetter */
+ [&](const Function &F) {
+ return AG.getAnalysis<DominatorTreeAnalysis>(F);
+ },
+ /* PDTGetter */
+ [&](const Function &F) {
+ return AG.getAnalysis<PostDominatorTreeAnalysis>(F);
+ }),
AG(AG), CGSCC(CGSCC) {}
/// A map type from opcodes to instructions with this opcode.
diff --git a/llvm/test/Transforms/Attributor/dereferenceable-2.ll b/llvm/test/Transforms/Attributor/dereferenceable-2.ll
index 11122e081c42..7ffc837caadc 100644
--- a/llvm/test/Transforms/Attributor/dereferenceable-2.ll
+++ b/llvm/test/Transforms/Attributor/dereferenceable-2.ll
@@ -1,4 +1,5 @@
; RUN: opt < %s -attributor --attributor-disable=false -S | FileCheck %s --check-prefix=ATTRIBUTOR
+; RUN: opt < %s -passes=attributor --attributor-disable=false -S | FileCheck %s --check-prefix=ATTRIBUTOR_CGSCC_NPM
; Copied from Transforms/InferFunctionAttrs/dereferenceable.ll
; Determine dereference-ability before unused loads get deleted:
@@ -354,3 +355,47 @@ define void @
diff erent_size2(i32* %arg) {
store double 0.000000e+00, double* %arg-cast
ret void
}
+
+; Make use of MustBeExecuted Explorer
+;
+; [CFG]
+; entry
+; / \
+; l1 l2
+; | X |
+; l3 l4
+; \ /
+; l5
+; / \
+; l6 l7
+; \ /
+; end
+; According to the above CFG, we can see that instructions in l5 Block must be executed.
+; Therefore, %p must be dereferenced.
+;
+; ATTRIBUTOR_CGSCC_NPM-LABEL: define i32 @require_cfg_analysis(i32 %c, i32* {{.*}} dereferenceable(4) %p)
+define i32 @require_cfg_analysis(i32 %c, i32* %p) {
+ %tobool1 = icmp eq i32 %c, 0
+ br i1 %tobool1, label %l1, label %l2
+l1:
+ %tobool2 = icmp eq i32 %c, 1
+ br i1 %tobool2, label %l3, label %l4
+l2:
+ %tobool3 = icmp eq i32 %c, 2
+ br i1 %tobool3, label %l3, label %l4
+l3:
+ br label %l5
+l4:
+ br label %l5
+l5:
+ %tobool4 = icmp eq i32 %c, 4
+ br i1 %tobool4, label %l6, label %l7
+l6:
+ store i32 0, i32* %p
+ br label %end
+l7:
+ store i32 1, i32* %p
+ br label %end
+end:
+ ret i32 1
+}
More information about the llvm-commits
mailing list