[llvm] r293661 - [Instcombine] Combine consecutive identical fences
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 31 10:09:05 PST 2017
Author: davide
Date: Tue Jan 31 12:09:05 2017
New Revision: 293661
URL: http://llvm.org/viewvc/llvm-project?rev=293661&view=rev
Log:
[Instcombine] Combine consecutive identical fences
Differential Revision: https://reviews.llvm.org/D29314
Added:
llvm/trunk/test/Transforms/InstCombine/consecutive-fences.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=293661&r1=293660&r2=293661&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Tue Jan 31 12:09:05 2017
@@ -3268,6 +3268,15 @@ Instruction *InstCombiner::visitCallInst
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) {
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=293661&r1=293660&r2=293661&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Tue Jan 31 12:09:05 2017
@@ -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);
Added: llvm/trunk/test/Transforms/InstCombine/consecutive-fences.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/consecutive-fences.ll?rev=293661&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/consecutive-fences.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/consecutive-fences.ll Tue Jan 31 12:09:05 2017
@@ -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
+}
More information about the llvm-commits
mailing list