[Instcombine] Combine consecutive identical fences

Differential Revision:  https://reviews.llvm.org/D29314

llvm-svn: 293661
This commit is contained in:
Davide Italiano 2017-01-31 18:09:05 +00:00
parent c0eeee7a78
commit aec4617dc8
3 changed files with 57 additions and 0 deletions

View File

@ -3268,6 +3268,15 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
return visitCallSite(II);
}
// Fence instruction simplification
Instruction *InstCombiner::visitFenceInst(FenceInst &FI) {
// Remove identical consecutive fences.
if (auto *NFI = dyn_cast<FenceInst>(FI.getNextNode()))
if (FI.isIdenticalTo(NFI))
return eraseInstFromFunction(FI);
return nullptr;
}
// InvokeInst simplification
//
Instruction *InstCombiner::visitInvokeInst(InvokeInst &II) {

View File

@ -289,6 +289,7 @@ public:
Instruction *visitLoadInst(LoadInst &LI);
Instruction *visitStoreInst(StoreInst &SI);
Instruction *visitBranchInst(BranchInst &BI);
Instruction *visitFenceInst(FenceInst &FI);
Instruction *visitSwitchInst(SwitchInst &SI);
Instruction *visitReturnInst(ReturnInst &RI);
Instruction *visitInsertValueInst(InsertValueInst &IV);

View File

@ -0,0 +1,47 @@
; RUN: opt -instcombine -S %s | FileCheck %s
; Make sure we collapse the fences in this case
; CHECK-LABEL: define void @tinkywinky
; CHECK-NEXT: fence seq_cst
; CHECK-NEXT: fence singlethread acquire
; CHECK-NEXT: ret void
; CHECK-NEXT: }
define void @tinkywinky() {
fence seq_cst
fence seq_cst
fence seq_cst
fence singlethread acquire
fence singlethread acquire
fence singlethread acquire
ret void
}
; CHECK-LABEL: define void @dipsy
; CHECK-NEXT: fence seq_cst
; CHECK-NEXT: fence singlethread seq_cst
; CHECK-NEXT: ret void
; CHECK-NEXT: }
define void @dipsy() {
fence seq_cst
fence singlethread seq_cst
ret void
}
; CHECK-LABEL: define void @patatino
; CHECK-NEXT: fence acquire
; CHECK-NEXT: fence seq_cst
; CHECK-NEXT: fence acquire
; CHECK-NEXT: fence seq_cst
; CHECK-NEXT: ret void
; CHECK-NEXT: }
define void @patatino() {
fence acquire
fence seq_cst
fence acquire
fence seq_cst
ret void
}