diff options
author | Owen Anderson <resistor@mac.com> | 2013-10-03 21:08:05 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2013-10-03 21:08:05 +0000 |
commit | 5797bfd4a3392738b27796162d526b0e37dd1e9f (patch) | |
tree | b0e9a1b03103c41f4175cc42bb8697be207e0fb7 /llvm/lib/Transforms | |
parent | 811bfe6395e041ec619a6a457e13d8b53a762d7f (diff) | |
download | bcm5719-llvm-5797bfd4a3392738b27796162d526b0e37dd1e9f.tar.gz bcm5719-llvm-5797bfd4a3392738b27796162d526b0e37dd1e9f.zip |
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
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index a35631fc15c..01894cbfdc1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -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()) { |