mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-06 09:44:39 +00:00
Canonicalization for @llvm.assume
Adds simple logical canonicalization of assumption intrinsics to instcombine, currently: - invariant(a && b) -> invariant(a); invariant(b) - invariant(!(a || b)) -> invariant(!a); invariant(!b) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213977 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a7f2c540fa
commit
5cb8ab5b5a
@ -994,6 +994,23 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||
return EraseInstFromFunction(CI);
|
||||
break;
|
||||
}
|
||||
case Intrinsic::assume: {
|
||||
// Canonicalize assume(a && b) -> assume(a); assume(b);
|
||||
Value *IIOperand = II->getArgOperand(0), *A, *B,
|
||||
*AssumeIntrinsic = II->getCalledValue();
|
||||
if (match(IIOperand, m_And(m_Value(A), m_Value(B)))) {
|
||||
Builder->CreateCall(AssumeIntrinsic, A, II->getName());
|
||||
Builder->CreateCall(AssumeIntrinsic, B, II->getName());
|
||||
return EraseInstFromFunction(*II);
|
||||
}
|
||||
// assume(!(a || b)) -> assume(!a); assume(!b);
|
||||
if (match(IIOperand, m_Not(m_Or(m_Value(A), m_Value(B))))) {
|
||||
Builder->CreateCall(AssumeIntrinsic, Builder->CreateNot(A), II->getName());
|
||||
Builder->CreateCall(AssumeIntrinsic, Builder->CreateNot(B), II->getName());
|
||||
return EraseInstFromFunction(*II);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return visitCallSite(II);
|
||||
|
43
test/Transforms/InstCombine/assume.ll
Normal file
43
test/Transforms/InstCombine/assume.ll
Normal file
@ -0,0 +1,43 @@
|
||||
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @llvm.assume(i1) #1
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define i32 @can1(i1 %a, i1 %b, i1 %c) {
|
||||
entry:
|
||||
%and1 = and i1 %a, %b
|
||||
%and = and i1 %and1, %c
|
||||
tail call void @llvm.assume(i1 %and)
|
||||
|
||||
; CHECK-LABEL: @can1
|
||||
; CHECK: call void @llvm.assume(i1 %a)
|
||||
; CHECK: call void @llvm.assume(i1 %b)
|
||||
; CHECK: call void @llvm.assume(i1 %c)
|
||||
; CHECK: ret i32
|
||||
|
||||
ret i32 5
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define i32 @can2(i1 %a, i1 %b, i1 %c) {
|
||||
entry:
|
||||
%v = or i1 %a, %b
|
||||
%w = xor i1 %v, 1
|
||||
tail call void @llvm.assume(i1 %w)
|
||||
|
||||
; CHECK-LABEL: @can2
|
||||
; CHECK: %[[V1:[^ ]+]] = xor i1 %a, true
|
||||
; CHECK: call void @llvm.assume(i1 %[[V1]])
|
||||
; CHECK: %[[V2:[^ ]+]] = xor i1 %b, true
|
||||
; CHECK: call void @llvm.assume(i1 %[[V2]])
|
||||
; CHECK: ret i32
|
||||
|
||||
ret i32 5
|
||||
}
|
||||
|
||||
attributes #0 = { nounwind uwtable }
|
||||
attributes #1 = { nounwind }
|
||||
|
Loading…
x
Reference in New Issue
Block a user