[llvm] r293061 - [InstCombine] Canonicalize guards for NOT OR condition
Artur Pilipenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 06:45:12 PST 2017
Author: apilipenko
Date: Wed Jan 25 08:45:12 2017
New Revision: 293061
URL: http://llvm.org/viewvc/llvm-project?rev=293061&view=rev
Log:
[InstCombine] Canonicalize guards for NOT OR condition
This is a partial fix for Bug 31520 - [guards] canonicalize guards in instcombine
Reviewed By: apilipenko
Differential Revision: https://reviews.llvm.org/D29075
Patch by Maxim Kazantsev.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/call-guard.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=293061&r1=293060&r2=293061&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Jan 25 08:45:12 2017
@@ -2989,6 +2989,18 @@ Instruction *InstCombiner::visitCallInst
GuardB->setCallingConv(CC);
return eraseInstFromFunction(*II);
}
+
+ // guard(!(a || b)) -> guard(!a); guard(!b);
+ if (match(IIOperand, m_Not(m_Or(m_Value(A), m_Value(B))))) {
+ CallInst *GuardA = Builder->CreateCall(
+ GuardIntrinsic, Builder->CreateNot(A), {DeoptOB}, II->getName());
+ CallInst *GuardB = Builder->CreateCall(
+ GuardIntrinsic, Builder->CreateNot(B), {DeoptOB}, II->getName());
+ auto CC = II->getCallingConv();
+ GuardA->setCallingConv(CC);
+ GuardB->setCallingConv(CC);
+ return eraseInstFromFunction(*II);
+ }
break;
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/call-guard.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/call-guard.ll?rev=293061&r1=293060&r2=293061&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/call-guard.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/call-guard.ll Wed Jan 25 08:45:12 2017
@@ -48,3 +48,29 @@ define void @test_guard_and_non_default_
call cc99 void(i1, ...) @llvm.experimental.guard( i1 %C )[ "deopt"() ]
ret void
}
+
+define void @test_guard_not_or(i1 %A, i1 %B) {
+; CHECK-LABEL: @test_guard_not_or(
+; CHECK-NEXT: %1 = xor i1 %A, true
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %1) [ "deopt"() ]
+; CHECK-NEXT: %2 = xor i1 %B, true
+; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %2) [ "deopt"() ]
+; CHECK-NEXT: ret void
+ %C = or i1 %A, %B
+ %D = xor i1 %C, true
+ call void(i1, ...) @llvm.experimental.guard( i1 %D )[ "deopt"() ]
+ ret void
+}
+
+define void @test_guard_not_or_non_default_cc(i1 %A, i1 %B) {
+; CHECK-LABEL: @test_guard_not_or_non_default_cc(
+; CHECK-NEXT: %1 = xor i1 %A, true
+; CHECK-NEXT: call cc99 void (i1, ...) @llvm.experimental.guard(i1 %1) [ "deopt"() ]
+; CHECK-NEXT: %2 = xor i1 %B, true
+; CHECK-NEXT: call cc99 void (i1, ...) @llvm.experimental.guard(i1 %2) [ "deopt"() ]
+; CHECK-NEXT: ret void
+ %C = or i1 %A, %B
+ %D = xor i1 %C, true
+ call cc99 void(i1, ...) @llvm.experimental.guard( i1 %D )[ "deopt"() ]
+ ret void
+}
More information about the llvm-commits
mailing list