[PATCH] D29074: Canonicalize guards for AND condition
Artur Pilipenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 06:32:14 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293058: [InstCombine] Canonicalize guards for AND condition (authored by apilipenko).
Changed prior to commit:
https://reviews.llvm.org/D29074?vs=85718&id=85744#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29074
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
@@ -28,3 +28,23 @@
call void(i1, ...) @llvm.experimental.guard( i1 %B )[ "deopt"() ]
ret void
}
+
+define void @test_guard_and(i1 %A, i1 %B) {
+; CHECK-LABEL: @test_guard_and(
+; 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
+ %C = and i1 %A, %B
+ call void(i1, ...) @llvm.experimental.guard( i1 %C )[ "deopt"() ]
+ ret void
+}
+
+define void @test_guard_and_non_default_cc(i1 %A, i1 %B) {
+; CHECK-LABEL: @test_guard_and_non_default_cc(
+; CHECK-NEXT: call cc99 void (i1, ...) @llvm.experimental.guard(i1 %A) [ "deopt"() ]
+; CHECK-NEXT: call cc99 void (i1, ...) @llvm.experimental.guard(i1 %B) [ "deopt"() ]
+; CHECK-NEXT: ret void
+ %C = and i1 %A, %B
+ call cc99 void(i1, ...) @llvm.experimental.guard( i1 %C )[ "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
@@ -2878,6 +2878,23 @@
if (match(II->getNextNode(),
m_Intrinsic<Intrinsic::experimental_guard>(m_Specific(IIOperand))))
return eraseInstFromFunction(*II);
+
+ // Canonicalize guard(a && b) -> guard(a); guard(b);
+ // Note: New guard intrinsics created here are registered by
+ // the InstCombineIRInserter object.
+ Function *GuardIntrinsic = II->getCalledFunction();
+ Value *A, *B;
+ OperandBundleDef DeoptOB(*II->getOperandBundle(LLVMContext::OB_deopt));
+ if (match(IIOperand, m_And(m_Value(A), m_Value(B)))) {
+ CallInst *GuardA =
+ Builder->CreateCall(GuardIntrinsic, A, {DeoptOB}, II->getName());
+ CallInst *GuardB =
+ Builder->CreateCall(GuardIntrinsic, B, {DeoptOB}, II->getName());
+ auto CC = II->getCallingConv();
+ GuardA->setCallingConv(CC);
+ GuardB->setCallingConv(CC);
+ return eraseInstFromFunction(*II);
+ }
break;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29074.85744.patch
Type: text/x-patch
Size: 2361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170125/abe15e2c/attachment.bin>
More information about the llvm-commits
mailing list