1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

Pull fptrunc's upwards through selects when one of the select's selectands was a constant. This has a number of benefits, including producing small immediates (easier to materialize, smaller constant pools) as well as being more likely to allow the fptrunc to fuse with a preceding instruction (truncating selects are unusual).

llvm-svn: 191929
This commit is contained in:
Owen Anderson 2013-10-03 21:08:05 +00:00
parent 957eba35f2
commit 5e2eba8c18
2 changed files with 25 additions and 0 deletions

View File

@ -1229,6 +1229,19 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
}
}
// (fptrunc (select cond, R1, Cst)) -->
// (select cond, (fptrunc R1), (fptrunc Cst))
SelectInst *SI = dyn_cast<SelectInst>(CI.getOperand(0));
if (SI &&
(isa<ConstantFP>(SI->getOperand(1)) ||
isa<ConstantFP>(SI->getOperand(2)))) {
Value *LHSTrunc = Builder->CreateFPTrunc(SI->getOperand(1),
CI.getType());
Value *RHSTrunc = Builder->CreateFPTrunc(SI->getOperand(2),
CI.getType());
return SelectInst::Create(SI->getOperand(0), LHSTrunc, RHSTrunc);
}
IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI.getOperand(0));
if (II) {
switch (II->getIntrinsicID()) {

View File

@ -31,4 +31,16 @@ define half @test4(float %a) {
ret half %c
}
; CHECK: test5
define half @test5(float %a, float %b, float %c) {
; CHECK: fcmp ogt
; CHECK: fptrunc
; CHECK: select
; CHECK: half 0xH3C00
%d = fcmp ogt float %a, %b
%e = select i1 %d, float %c, float 1.0
%f = fptrunc float %e to half
ret half %f
}
declare float @llvm.fabs.f32(float) nounwind readonly