[polly] r276263 - BlockGenerator: remove dead instructions in normal statements
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 21 04:48:36 PDT 2016
Author: grosser
Date: Thu Jul 21 06:48:36 2016
New Revision: 276263
URL: http://llvm.org/viewvc/llvm-project?rev=276263&view=rev
Log:
BlockGenerator: remove dead instructions in normal statements
This ensures that no trivially dead code is generated. This is not only cleaner,
but also avoids troubles in case code is generated in a separate function and
some of this dead code contains references to values that are not available.
This issue may happen, in case the memory access functions have been updated
and old getelementptr instructions remain in the code. With normal Polly,
a test case is difficult to draft, but the upcoming GPU code generation can
possibly trigger such problems. We will later extend this dead-code elimination
to region and vector statements.
Modified:
polly/trunk/include/polly/CodeGen/BlockGenerators.h
polly/trunk/lib/CodeGen/BlockGenerators.cpp
polly/trunk/test/ScopInfo/int2ptr_ptr2int_2.ll
Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=276263&r1=276262&r2=276263&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Thu Jul 21 06:48:36 2016
@@ -540,6 +540,12 @@ protected:
///
/// @returns false, iff @p Inst can be synthesized in @p Stmt.
bool canSyntheziseInStmt(ScopStmt &Stmt, Instruction *Inst);
+
+ /// @brief Remove dead instructions generated for BB
+ ///
+ /// @param BB The basic block code for which code has been generated.
+ /// @param BBMap A local map from old to new instructions.
+ void removeDeadInstructions(BasicBlock *BB, ValueMapT &BBMap);
};
/// @brief Generate a new vector basic block for a polyhedral statement.
Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=276263&r1=276262&r2=276263&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Thu Jul 21 06:48:36 2016
@@ -278,6 +278,27 @@ void BlockGenerator::copyInstruction(Sco
copyInstScalar(Stmt, Inst, BBMap, LTS);
}
+void BlockGenerator::removeDeadInstructions(BasicBlock *BB, ValueMapT &BBMap) {
+ for (auto I = BB->rbegin(), E = BB->rend(); I != E; I++) {
+ Instruction *Inst = &*I;
+ Value *NewVal = BBMap[Inst];
+
+ if (!NewVal)
+ continue;
+
+ Instruction *NewInst = dyn_cast<Instruction>(NewVal);
+
+ if (!NewInst)
+ continue;
+
+ if (!isInstructionTriviallyDead(NewInst))
+ continue;
+
+ BBMap.erase(Inst);
+ NewInst->eraseFromParent();
+ }
+}
+
void BlockGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S,
isl_id_to_ast_expr *NewAccesses) {
assert(Stmt.isBlockStmt() &&
@@ -287,6 +308,7 @@ void BlockGenerator::copyStmt(ScopStmt &
BasicBlock *BB = Stmt.getBasicBlock();
copyBB(Stmt, BB, BBMap, LTS, NewAccesses);
+ removeDeadInstructions(BB, BBMap);
}
BasicBlock *BlockGenerator::splitBB(BasicBlock *BB) {
Modified: polly/trunk/test/ScopInfo/int2ptr_ptr2int_2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/int2ptr_ptr2int_2.ll?rev=276263&r1=276262&r2=276263&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/int2ptr_ptr2int_2.ll (original)
+++ polly/trunk/test/ScopInfo/int2ptr_ptr2int_2.ll Thu Jul 21 06:48:36 2016
@@ -21,10 +21,6 @@
; IR: polly.stmt.for.body:
; IR-NEXT: %p_tmp = ptrtoint i64* %scevgep to i64
; IR-NEXT: %p_add = add nsw i64 %p_tmp, 1
-; IR-NEXT: %p_tmp1 = inttoptr i64 %26 to i64*
-; IR-NEXT: %p_add.ptr2 = getelementptr inbounds i64, i64* %p_tmp1, i64 1
-; IR-NEXT: %p_tmp2 = ptrtoint i64* %p_add.ptr2 to i64
-; IR-NEXT: %p_arrayidx = getelementptr inbounds i64, i64* %B, i64 %p_tmp2
; IR-NEXT: %p_arrayidx3 = getelementptr inbounds i64, i64* %A, i64 %p_add
; IR-NEXT: %tmp4_p_scalar_ = load i64, i64* %p_arrayidx3
; IR-NEXT: %p_add4 = add nsw i64 %tmp4_p_scalar_, %polly.preload.tmp3.merge
@@ -32,7 +28,6 @@
;
; IR: polly.loop_preheader:
; IR-NEXT: %scevgep = getelementptr i64, i64* %ptr, i64 1
-; IR-NEXT: %26 = add i64 %val, 1
; IR-NEXT: br label %polly.loop_header
;
;
More information about the llvm-commits
mailing list