summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Pilipenko <apilipenko@azulsystems.com>2017-01-25 14:12:12 +0000
committerArtur Pilipenko <apilipenko@azulsystems.com>2017-01-25 14:12:12 +0000
commite812ca00bbd50be94f9e0110be5f99b72b2efc07 (patch)
treec8f6629ad29b090d2cf9507f6e2503b5ea572a5e
parent91834227a3d58ecdb9e3f7300f587ab45c32ba06 (diff)
downloadbcm5719-llvm-e812ca00bbd50be94f9e0110be5f99b72b2efc07.tar.gz
bcm5719-llvm-e812ca00bbd50be94f9e0110be5f99b72b2efc07.zip
[InstCombine] Allow InstrCombine to remove one of adjacent guards if they are equivalent
This is a partial fix for Bug 31520 - [guards] canonicalize guards in instcombine Reviewed By: majnemer, apilipenko Differential Revision: https://reviews.llvm.org/D29071 Patch by Maxim Kazantsev. llvm-svn: 293056
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp10
-rw-r--r--llvm/test/Transforms/InstCombine/call-guard.ll30
2 files changed, 40 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 6b03b682bca..679596766fc 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2870,6 +2870,16 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// TODO: relocate((gep p, C, C2, ...)) -> gep(relocate(p), C, C2, ...)
break;
}
+
+ case Intrinsic::experimental_guard: {
+ Value *IIOperand = II->getArgOperand(0);
+
+ // Remove a guard if it is immediately followed by an identical guard.
+ if (match(II->getNextNode(),
+ m_Intrinsic<Intrinsic::experimental_guard>(m_Specific(IIOperand))))
+ return eraseInstFromFunction(*II);
+ break;
+ }
}
return visitCallSite(II);
diff --git a/llvm/test/Transforms/InstCombine/call-guard.ll b/llvm/test/Transforms/InstCombine/call-guard.ll
new file mode 100644
index 00000000000..18da465e606
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/call-guard.ll
@@ -0,0 +1,30 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @llvm.experimental.guard(i1, ...)
+
+define void @test_guard_adjacent(i1 %A) {
+; CHECK-LABEL: @test_guard_adjacent(
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %A) [ "deopt"() ]
+; CHECK-NEXT: ret void
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ ret void
+}
+
+define void @test_guard_adjacent_neg(i1 %A, i1 %B) {
+; CHECK-LABEL: @test_guard_adjacent_neg(
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %A) [ "deopt"() ]
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %B) [ "deopt"() ]
+; CHECK-NEXT: ret void
+ call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard( i1 %B )[ "deopt"() ]
+ ret void
+}
OpenPOWER on IntegriCloud