mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-01 01:31:26 +00:00
CodePrepare: Do not require canonical induction variables for scev based mode
llvm-svn: 177593
This commit is contained in:
parent
cd4ebb7639
commit
5bfa4f8eb8
@ -13,6 +13,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "polly/LinkAllPasses.h"
|
||||
#include "polly/CodeGen/BlockGenerators.h"
|
||||
#include "polly/Support/ScopHelper.h"
|
||||
|
||||
#include "llvm/IR/Instruction.h"
|
||||
@ -47,6 +48,7 @@ class CodePreparation : public FunctionPass {
|
||||
|
||||
// LoopInfo to compute canonical induction variable.
|
||||
LoopInfo *LI;
|
||||
ScalarEvolution *SE;
|
||||
|
||||
// Clear the context.
|
||||
void clear();
|
||||
@ -92,11 +94,21 @@ bool CodePreparation::eliminatePHINodes(Function &F) {
|
||||
for (BasicBlock::iterator iib = ibb->begin(), iie = ibb->getFirstNonPHI();
|
||||
iib != iie; ++iib)
|
||||
if (PHINode *PN = cast<PHINode>(iib)) {
|
||||
if (Loop *L = LI->getLoopFor(ibb)) {
|
||||
// Induction variable will be preserved.
|
||||
if (L->getCanonicalInductionVariable() == PN) {
|
||||
PreservedPNs.push_back(PN);
|
||||
continue;
|
||||
if (SCEVCodegen) {
|
||||
if (SE->isSCEVable(PN->getType())) {
|
||||
const SCEV *S = SE->getSCEV(PN);
|
||||
if (!isa<SCEVUnknown>(S) && !isa<SCEVCouldNotCompute>(S)) {
|
||||
PreservedPNs.push_back(PN);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Loop *L = LI->getLoopFor(ibb)) {
|
||||
// Induction variable will be preserved.
|
||||
if (L->getCanonicalInductionVariable() == PN) {
|
||||
PreservedPNs.push_back(PN);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,6 +148,7 @@ bool CodePreparation::eliminatePHINodes(Function &F) {
|
||||
|
||||
void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<LoopInfo>();
|
||||
AU.addRequired<ScalarEvolution>();
|
||||
|
||||
AU.addPreserved<LoopInfo>();
|
||||
AU.addPreserved<RegionInfo>();
|
||||
@ -145,6 +158,7 @@ void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
|
||||
bool CodePreparation::runOnFunction(Function &F) {
|
||||
LI = &getAnalysis<LoopInfo>();
|
||||
SE = &getAnalysis<ScalarEvolution>();
|
||||
|
||||
splitEntryBlockForAlloca(&F.getEntryBlock(), this);
|
||||
|
||||
|
53
polly/test/CodePreparation/if_condition.ll
Normal file
53
polly/test/CodePreparation/if_condition.ll
Normal file
@ -0,0 +1,53 @@
|
||||
; RUN: opt %loadPolly -polly-prepare -S < %s | FileCheck %s
|
||||
; RUN: opt %loadPolly -polly-prepare -S -polly-codegen-scev < %s | FileCheck %s
|
||||
|
||||
; void f(long A[], long N) {
|
||||
; long i;
|
||||
; for (i = 0; i < N; ++i)
|
||||
; A[i] = i;
|
||||
; }
|
||||
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
define void @f(i64* %A, i64 %N) nounwind {
|
||||
entry:
|
||||
fence seq_cst
|
||||
br label %for.i
|
||||
; CHECK: entry:
|
||||
; CHECK: %value.reg2mem = alloca i64
|
||||
; CHECK: br label %entry.split
|
||||
|
||||
for.i:
|
||||
%indvar = phi i64 [ 0, %entry ], [ %indvar.next, %merge ]
|
||||
%scevgep = getelementptr i64* %A, i64 %indvar
|
||||
%cmp = icmp eq i64 %indvar, 3
|
||||
br i1 %cmp, label %then, label %else
|
||||
|
||||
then:
|
||||
%add_two = add i64 %indvar, 2
|
||||
br label %merge
|
||||
; CHECK: then:
|
||||
; CHECK: %add_two = add i64 %indvar, 2
|
||||
; CHECK: store i64 %add_two, i64* %value.reg2mem
|
||||
; CHECK: br label %merge
|
||||
|
||||
else:
|
||||
%add_three = add i64 %indvar, 4
|
||||
br label %merge
|
||||
; CHECK: else:
|
||||
; CHECK: %add_three = add i64 %indvar, 4
|
||||
; CHECK: store i64 %add_three, i64* %value.reg2mem
|
||||
; CHECK: br label %merge
|
||||
|
||||
merge:
|
||||
%value = phi i64 [ %add_two, %then ], [ %add_three, %else ]
|
||||
store i64 %value, i64* %scevgep
|
||||
%indvar.next = add nsw i64 %indvar, 1
|
||||
%exitcond = icmp eq i64 %indvar.next, %N
|
||||
br i1 %exitcond, label %return, label %for.i
|
||||
|
||||
return:
|
||||
fence seq_cst
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue
Block a user