1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 13:11:39 +01:00

[InstCombine] Canonicalize guards for AND condition

This is a partial fix for Bug 31520 - [guards] canonicalize guards in instcombine

Reviewed By: apilipenko

Differential Revision: https://reviews.llvm.org/D29074

Patch by Maxim Kazantsev.

llvm-svn: 293058
This commit is contained in:
Artur Pilipenko 2017-01-25 14:20:52 +00:00
parent 8d5f1040c3
commit 71132836b4
2 changed files with 37 additions and 0 deletions

View File

@ -2878,6 +2878,23 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
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;
}
}

View File

@ -28,3 +28,23 @@ define void @test_guard_adjacent_neg(i1 %A, i1 %B) {
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
}