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

Artur Pilipenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 06:23:23 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL293056: [InstCombine] Allow InstrCombine to remove one of adjacent guards if they areā€¦ (authored by apilipenko).

Changed prior to commit:
  https://reviews.llvm.org/D29071?vs=85690&id=85742#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29071

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


Index: llvm/trunk/test/Transforms/InstCombine/call-guard.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/call-guard.ll
+++ llvm/trunk/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: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/trunk/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.85742.patch
Type: text/x-patch
Size: 2457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170125/1d0b8d7c/attachment.bin>


More information about the llvm-commits mailing list