Skip to content

Commit 134e7e3

Browse files
okuraofvegetablememfrob
authored and
memfrob
committed
[Attributor] Make use of analysis in the MustBeExecutedExplorer
This commit was made to settle [[ llvm/llvm-project#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
1 parent c4badd2 commit 134e7e3

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#include "llvm/Analysis/InlineCost.h"
108108
#include "llvm/Analysis/LazyCallGraph.h"
109109
#include "llvm/Analysis/MustExecute.h"
110+
#include "llvm/Analysis/PostDominators.h"
110111
#include "llvm/Analysis/TargetLibraryInfo.h"
111112
#include "llvm/Analysis/TargetTransformInfo.h"
112113
#include "llvm/IR/CallSite.h"
@@ -566,8 +567,19 @@ struct InformationCache {
566567
InformationCache(const Module &M, AnalysisGetter &AG,
567568
SetVector<Function *> *CGSCC)
568569
: DL(M.getDataLayout()),
569-
Explorer(/* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
570-
/* ExploreCFGBackward */ true),
570+
Explorer(
571+
/* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
572+
/* ExploreCFGBackward */ true,
573+
/* LIGetter */
574+
[&](const Function &F) { return AG.getAnalysis<LoopAnalysis>(F); },
575+
/* DTGetter */
576+
[&](const Function &F) {
577+
return AG.getAnalysis<DominatorTreeAnalysis>(F);
578+
},
579+
/* PDTGetter */
580+
[&](const Function &F) {
581+
return AG.getAnalysis<PostDominatorTreeAnalysis>(F);
582+
}),
571583
AG(AG), CGSCC(CGSCC) {}
572584

573585
/// A map type from opcodes to instructions with this opcode.

llvm/test/Transforms/Attributor/dereferenceable-2.ll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: opt < %s -attributor --attributor-disable=false -S | FileCheck %s --check-prefix=ATTRIBUTOR
2+
; RUN: opt < %s -passes=attributor --attributor-disable=false -S | FileCheck %s --check-prefix=ATTRIBUTOR_CGSCC_NPM
23
; Copied from Transforms/InferFunctionAttrs/dereferenceable.ll
34

45
; Determine dereference-ability before unused loads get deleted:
@@ -354,3 +355,47 @@ define void @different_size2(i32* %arg) {
354355
store double 0.000000e+00, double* %arg-cast
355356
ret void
356357
}
358+
359+
; Make use of MustBeExecuted Explorer
360+
;
361+
; [CFG]
362+
; entry
363+
; / \
364+
; l1 l2
365+
; | X |
366+
; l3 l4
367+
; \ /
368+
; l5
369+
; / \
370+
; l6 l7
371+
; \ /
372+
; end
373+
; According to the above CFG, we can see that instructions in l5 Block must be executed.
374+
; Therefore, %p must be dereferenced.
375+
;
376+
; ATTRIBUTOR_CGSCC_NPM-LABEL: define i32 @require_cfg_analysis(i32 %c, i32* {{.*}} dereferenceable(4) %p)
377+
define i32 @require_cfg_analysis(i32 %c, i32* %p) {
378+
%tobool1 = icmp eq i32 %c, 0
379+
br i1 %tobool1, label %l1, label %l2
380+
l1:
381+
%tobool2 = icmp eq i32 %c, 1
382+
br i1 %tobool2, label %l3, label %l4
383+
l2:
384+
%tobool3 = icmp eq i32 %c, 2
385+
br i1 %tobool3, label %l3, label %l4
386+
l3:
387+
br label %l5
388+
l4:
389+
br label %l5
390+
l5:
391+
%tobool4 = icmp eq i32 %c, 4
392+
br i1 %tobool4, label %l6, label %l7
393+
l6:
394+
store i32 0, i32* %p
395+
br label %end
396+
l7:
397+
store i32 1, i32* %p
398+
br label %end
399+
end:
400+
ret i32 1
401+
}

0 commit comments

Comments
 (0)