mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
[InstCombine] Employ AliasAnalysis in FindAvailableLoadedValue
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241887 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ad4d73941a
commit
86ef198476
@ -15,6 +15,7 @@
|
||||
#ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
|
||||
#define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
|
||||
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/Analysis/AssumptionCache.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/TargetFolder.h"
|
||||
@ -177,6 +178,8 @@ private:
|
||||
// Mode in which we are running the combiner.
|
||||
const bool MinimizeSize;
|
||||
|
||||
AliasAnalysis *AA;
|
||||
|
||||
// Required analyses.
|
||||
// FIXME: These can never be null and should be references.
|
||||
AssumptionCache *AC;
|
||||
@ -192,10 +195,11 @@ private:
|
||||
|
||||
public:
|
||||
InstCombiner(InstCombineWorklist &Worklist, BuilderTy *Builder,
|
||||
bool MinimizeSize, AssumptionCache *AC, TargetLibraryInfo *TLI,
|
||||
bool MinimizeSize, AliasAnalysis *AA,
|
||||
AssumptionCache *AC, TargetLibraryInfo *TLI,
|
||||
DominatorTree *DT, const DataLayout &DL, LoopInfo *LI)
|
||||
: Worklist(Worklist), Builder(Builder), MinimizeSize(MinimizeSize),
|
||||
AC(AC), TLI(TLI), DT(DT), DL(DL), LI(LI), MadeIRChange(false) {}
|
||||
AA(AA), AC(AC), TLI(TLI), DT(DT), DL(DL), LI(LI), MadeIRChange(false) {}
|
||||
|
||||
/// \brief Run the combiner over the entire worklist until it is empty.
|
||||
///
|
||||
|
@ -751,7 +751,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
|
||||
BasicBlock::iterator BBI = &LI;
|
||||
AAMDNodes AATags;
|
||||
if (Value *AvailableVal = FindAvailableLoadedValue(Op, LI.getParent(), BBI,
|
||||
6, nullptr, &AATags)) {
|
||||
6, AA, &AATags)) {
|
||||
if (LoadInst *NLI = dyn_cast<LoadInst>(AvailableVal)) {
|
||||
unsigned KnownIDs[] = {
|
||||
LLVMContext::MD_tbaa,
|
||||
|
@ -2972,8 +2972,9 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
|
||||
|
||||
static bool
|
||||
combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist,
|
||||
AssumptionCache &AC, TargetLibraryInfo &TLI,
|
||||
DominatorTree &DT, LoopInfo *LI = nullptr) {
|
||||
AliasAnalysis *AA, AssumptionCache &AC,
|
||||
TargetLibraryInfo &TLI, DominatorTree &DT,
|
||||
LoopInfo *LI = nullptr) {
|
||||
// Minimizing size?
|
||||
bool MinimizeSize = F.hasFnAttribute(Attribute::MinSize);
|
||||
auto &DL = F.getParent()->getDataLayout();
|
||||
@ -2998,7 +2999,8 @@ combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist,
|
||||
if (prepareICWorklistFromFunction(F, DL, &TLI, Worklist))
|
||||
Changed = true;
|
||||
|
||||
InstCombiner IC(Worklist, &Builder, MinimizeSize, &AC, &TLI, &DT, DL, LI);
|
||||
InstCombiner IC(Worklist, &Builder, MinimizeSize,
|
||||
AA, &AC, &TLI, &DT, DL, LI);
|
||||
if (IC.run())
|
||||
Changed = true;
|
||||
|
||||
@ -3017,7 +3019,8 @@ PreservedAnalyses InstCombinePass::run(Function &F,
|
||||
|
||||
auto *LI = AM->getCachedResult<LoopAnalysis>(F);
|
||||
|
||||
if (!combineInstructionsOverFunction(F, Worklist, AC, TLI, DT, LI))
|
||||
// FIXME: The AliasAnalysis is not yet supported in the new pass manager
|
||||
if (!combineInstructionsOverFunction(F, Worklist, nullptr, AC, TLI, DT, LI))
|
||||
// No changes, all analyses are preserved.
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
@ -3050,6 +3053,7 @@ public:
|
||||
|
||||
void InstructionCombiningPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.setPreservesCFG();
|
||||
AU.addRequired<AliasAnalysis>();
|
||||
AU.addRequired<AssumptionCacheTracker>();
|
||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
@ -3061,6 +3065,7 @@ bool InstructionCombiningPass::runOnFunction(Function &F) {
|
||||
return false;
|
||||
|
||||
// Required analyses.
|
||||
auto AA = &getAnalysis<AliasAnalysis>();
|
||||
auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
|
||||
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
||||
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
@ -3069,7 +3074,7 @@ bool InstructionCombiningPass::runOnFunction(Function &F) {
|
||||
auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
|
||||
auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
|
||||
|
||||
return combineInstructionsOverFunction(F, Worklist, AC, TLI, DT, LI);
|
||||
return combineInstructionsOverFunction(F, Worklist, AA, AC, TLI, DT, LI);
|
||||
}
|
||||
|
||||
char InstructionCombiningPass::ID = 0;
|
||||
@ -3078,6 +3083,7 @@ INITIALIZE_PASS_BEGIN(InstructionCombiningPass, "instcombine",
|
||||
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
||||
INITIALIZE_PASS_END(InstructionCombiningPass, "instcombine",
|
||||
"Combine redundant instructions", false, false)
|
||||
|
||||
|
15
test/Transforms/InstCombine/load_combine_aa.ll
Normal file
15
test/Transforms/InstCombine/load_combine_aa.ll
Normal file
@ -0,0 +1,15 @@
|
||||
; RUN: opt -basicaa -instcombine -S < %s | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: @test_load_combine_aa(
|
||||
; CHECK: %[[V:.*]] = load i32, i32* %0
|
||||
; CHECK: store i32 0, i32* %3
|
||||
; CHECK: store i32 %[[V]], i32* %1
|
||||
; CHECK: store i32 %[[V]], i32* %2
|
||||
define void @test_load_combine_aa(i32*, i32*, i32*, i32* noalias) {
|
||||
%a = load i32, i32* %0
|
||||
store i32 0, i32* %3
|
||||
%b = load i32, i32* %0
|
||||
store i32 %a, i32* %1
|
||||
store i32 %b, i32* %2
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue
Block a user