diff options
author | Dinesh Dwivedi <dinesh.d@samsung.com> | 2014-05-15 06:13:40 +0000 |
---|---|---|
committer | Dinesh Dwivedi <dinesh.d@samsung.com> | 2014-05-15 06:13:40 +0000 |
commit | f675f4201b8a0e3060c1d08d1497ca431e1a0c74 (patch) | |
tree | 9f12501ad30ffde6778d0c7508301742f299ccc7 /llvm/lib/Transforms | |
parent | 837c16097e99d7b648fb983213485974d25fcf9c (diff) | |
download | bcm5719-llvm-f675f4201b8a0e3060c1d08d1497ca431e1a0c74.tar.gz bcm5719-llvm-f675f4201b8a0e3060c1d08d1497ca431e1a0c74.zip |
Added instcombine for 'MIN(MIN(A, 27), 93)' and 'MAX(MAX(A, 93), 27)'
MIN(MIN(A, 23), 97) -> MIN(A, 23)
MAX(MAX(A, 97), 23) -> MAX(A, 97)
Differential Revision: http://reviews.llvm.org/D3629
llvm-svn: 208849
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 50b5b3740f1..90525950ea6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -683,11 +683,27 @@ Instruction *InstCombiner::FoldSPFofSPF(Instruction *Inner, return ReplaceInstUsesWith(Outer, C); } - // TODO: MIN(MIN(A, 23), 97) + // MIN(MIN(A, 23), 97) -> MIN(A, 23) + // MAX(MAX(A, 97), 23) -> MAX(A, 97) + if (SPF1 == SPF2) { + if (ConstantInt *CB = dyn_cast<ConstantInt>(B)) { + if (ConstantInt *CC = dyn_cast<ConstantInt>(C)) { + APInt ACB = CB->getValue(); + APInt ACC = CC->getValue(); + if ((SPF1 == SPF_UMIN && ACB.ule(ACC)) || + (SPF1 == SPF_SMIN && ACB.sle(ACC)) || + (SPF1 == SPF_UMAX && ACB.uge(ACC)) || + (SPF1 == SPF_SMAX && ACB.sge(ACC))) + return ReplaceInstUsesWith(Outer, Inner); + } + } + } + + // TODO: MIN(MIN(A, 97), 23) -> MIN(A, 23) + // TODO: MAX(MAX(A, 23), 97) -> MAX(A, 97) return nullptr; } - /// foldSelectICmpAnd - If one of the constants is zero (we know they can't /// both be) and we have an icmp instruction with zero, and we have an 'and' /// with the non-constant value and a power of two we can turn the select |