Skip to content

Commit

Permalink
[InstCombine] Canonicalize guards for NOT OR condition
Browse files Browse the repository at this point in the history
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293061 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arpilipe committed Jan 25, 2017
1 parent a9c60bb commit c6141d3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,18 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
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;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/Transforms/InstCombine/call-guard.ll
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,29 @@ define void @test_guard_and_non_default_cc(i1 %A, i1 %B) {
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
}

0 comments on commit c6141d3

Please sign in to comment.