[llvm] r279538 - [InstSimplify] allow icmp with constant folds for splat vectors, part 1

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 10:30:57 PDT 2016


Author: spatel
Date: Tue Aug 23 12:30:56 2016
New Revision: 279538

URL: http://llvm.org/viewvc/llvm-project?rev=279538&view=rev
Log:
[InstSimplify] allow icmp with constant folds for splat vectors, part 1

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/icmp-constant.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=279538&r1=279537&r2=279538&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Aug 23 12:30:56 2016
@@ -2154,17 +2154,21 @@ computePointerICmp(const DataLayout &DL,
 
 static Value *simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS,
                                        Value *RHS) {
-  // FIXME: Use m_APInt here and below to allow splat vector folds.
-  ConstantInt *CI = dyn_cast<ConstantInt>(RHS);
-  if (!CI)
+  const APInt *C;
+  if (!match(RHS, m_APInt(C)))
     return nullptr;
 
   // Rule out tautological comparisons (eg., ult 0 or uge 0).
-  ConstantRange RHS_CR = ICmpInst::makeConstantRange(Pred, CI->getValue());
+  ConstantRange RHS_CR = ICmpInst::makeConstantRange(Pred, *C);
   if (RHS_CR.isEmptySet())
-    return ConstantInt::getFalse(CI->getContext());
+    return ConstantInt::getFalse(GetCompareTy(RHS));
   if (RHS_CR.isFullSet())
-    return ConstantInt::getTrue(CI->getContext());
+    return ConstantInt::getTrue(GetCompareTy(RHS));
+
+  // FIXME: Use m_APInt below here to allow splat vector folds.
+  ConstantInt *CI = dyn_cast<ConstantInt>(RHS);
+  if (!CI)
+    return nullptr;
 
   // Many binary operators with constant RHS have easy to compute constant
   // range.  Use them to check whether the comparison is a tautology.

Modified: llvm/trunk/test/Transforms/InstSimplify/icmp-constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/icmp-constant.ll?rev=279538&r1=279537&r2=279538&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/icmp-constant.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/icmp-constant.ll Tue Aug 23 12:30:56 2016
@@ -13,8 +13,7 @@ define i1 @tautological_ule(i8 %x) {
 
 define <2 x i1> @tautological_ule_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @tautological_ule_vec(
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ule <2 x i8> %x, <i8 -1, i8 -1>
-; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %cmp = icmp ule <2 x i8> %x, <i8 255, i8 255>
   ret <2 x i1> %cmp
@@ -30,8 +29,7 @@ define i1 @tautological_ugt(i8 %x) {
 
 define <2 x i1> @tautological_ugt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @tautological_ugt_vec(
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt <2 x i8> %x, <i8 -1, i8 -1>
-; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %cmp = icmp ugt <2 x i8> %x, <i8 255, i8 255>
   ret <2 x i1> %cmp




More information about the llvm-commits mailing list