[llvm] r293056 - [InstCombine] Allow InstrCombine to remove one of adjacent guards if they are equivalent

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


Author: apilipenko
Date: Wed Jan 25 08:12:12 2017
New Revision: 293056

URL: http://llvm.org/viewvc/llvm-project?rev=293056&view=rev
Log:
[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.

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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=293056&r1=293055&r2=293056&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Jan 25 08:12:12 2017
@@ -2870,6 +2870,16 @@ Instruction *InstCombiner::visitCallInst
     // 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);

Added: llvm/trunk/test/Transforms/InstCombine/call-guard.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/call-guard.ll?rev=293056&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/call-guard.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/call-guard.ll Wed Jan 25 08:12:12 2017
@@ -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
+}




More information about the llvm-commits mailing list