Index: llvm/include/llvm/Transforms/IPO/Attributor.h =================================================================== --- llvm/include/llvm/Transforms/IPO/Attributor.h +++ llvm/include/llvm/Transforms/IPO/Attributor.h @@ -106,6 +106,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" @@ -559,8 +560,19 @@ InformationCache(const Module &M, AnalysisGetter &AG, SetVector *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(F); }, + /* DTGetter */ + [&](const Function &F) { + return AG.getAnalysis(F); + }, + /* PDTGetter */ + [&](const Function &F) { + return AG.getAnalysis(F); + }), AG(AG), CGSCC(CGSCC) {} /// A map type from opcodes to instructions with this opcode. Index: llvm/test/Transforms/Attributor/dereferenceable-2.ll =================================================================== --- llvm/test/Transforms/Attributor/dereferenceable-2.ll +++ llvm/test/Transforms/Attributor/dereferenceable-2.ll @@ -354,3 +354,47 @@ 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-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 +}