llvm.org GIT mirror llvm / 405b046
[InstSimplify] allow icmp with constant folds for splat vectors, part 1 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279538 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 14 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
21532153
21542154 static Value *simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS,
21552155 Value *RHS) {
2156 // FIXME: Use m_APInt here and below to allow splat vector folds.
2156 const APInt *C;
2157 if (!match(RHS, m_APInt(C)))
2158 return nullptr;
2159
2160 // Rule out tautological comparisons (eg., ult 0 or uge 0).
2161 ConstantRange RHS_CR = ICmpInst::makeConstantRange(Pred, *C);
2162 if (RHS_CR.isEmptySet())
2163 return ConstantInt::getFalse(GetCompareTy(RHS));
2164 if (RHS_CR.isFullSet())
2165 return ConstantInt::getTrue(GetCompareTy(RHS));
2166
2167 // FIXME: Use m_APInt below here to allow splat vector folds.
21572168 ConstantInt *CI = dyn_cast(RHS);
21582169 if (!CI)
21592170 return nullptr;
2160
2161 // Rule out tautological comparisons (eg., ult 0 or uge 0).
2162 ConstantRange RHS_CR = ICmpInst::makeConstantRange(Pred, CI->getValue());
2163 if (RHS_CR.isEmptySet())
2164 return ConstantInt::getFalse(CI->getContext());
2165 if (RHS_CR.isFullSet())
2166 return ConstantInt::getTrue(CI->getContext());
21672171
21682172 // Many binary operators with constant RHS have easy to compute constant
21692173 // range. Use them to check whether the comparison is a tautology.
1212
1313 define <2 x i1> @tautological_ule_vec(<2 x i8> %x) {
1414 ; CHECK-LABEL: @tautological_ule_vec(
15 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i8> %x,
16 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
15 ; CHECK-NEXT: ret <2 x i1>
1716 ;
1817 %cmp = icmp ule <2 x i8> %x,
1918 ret <2 x i1> %cmp
2928
3029 define <2 x i1> @tautological_ugt_vec(<2 x i8> %x) {
3130 ; CHECK-LABEL: @tautological_ugt_vec(
32 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x,
33 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
31 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
3432 ;
3533 %cmp = icmp ugt <2 x i8> %x,
3634 ret <2 x i1> %cmp