[PATCH] D29071: Allow InstrCombine to remove one of adjacent guards if they are equivalent

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 20:45:15 PST 2017


mkazantsev updated this revision to Diff 85690.
mkazantsev marked an inline comment as done.
mkazantsev added a comment.

Added negative test.


https://reviews.llvm.org/D29071

Files:
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/call-guard.ll


Index: test/Transforms/InstCombine/call-guard.ll
===================================================================
--- test/Transforms/InstCombine/call-guard.ll
+++ 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
+}
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2870,6 +2870,16 @@
     // 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29071.85690.patch
Type: text/x-patch
Size: 2391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170125/66cd993b/attachment.bin>


More information about the llvm-commits mailing list