[llvm-commits] [llvm] r92788 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCasts.cpp test/Transforms/InstCombine/bswap.ll

Chris Lattner sabre at nondot.org
Tue Jan 5 14:01:41 PST 2010


Author: lattner
Date: Tue Jan  5 16:01:41 2010
New Revision: 92788

URL: http://llvm.org/viewvc/llvm-project?rev=92788&view=rev
Log:
remove two trunc xforms that are subsumed by EvaluateInDifferentType.
The only difference is that EvaluateInDifferentType checks to ensure
they are profitable before doing them :)

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/trunk/test/Transforms/InstCombine/bswap.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=92788&r1=92787&r2=92788&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Jan  5 16:01:41 2010
@@ -628,7 +628,6 @@
   return 0;
 }
 
-
 Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
   if (Instruction *Result = commonIntCastTransforms(CI))
     return Result;
@@ -646,41 +645,6 @@
     return new ICmpInst(ICmpInst::ICMP_NE, Src, Zero);
   }
 
-  // Optimize trunc(lshr(x, c)) to pull the shift through the truncate.
-  ConstantInt *ShAmtV = 0;
-  Value *ShiftOp = 0;
-  if (Src->hasOneUse() &&
-      match(Src, m_LShr(m_Value(ShiftOp), m_ConstantInt(ShAmtV)))) {
-    uint32_t ShAmt = ShAmtV->getLimitedValue(SrcBitWidth);
-    
-    // Get a mask for the bits shifting in.
-    APInt Mask(APInt::getLowBitsSet(SrcBitWidth, ShAmt).shl(DestBitWidth));
-    if (MaskedValueIsZero(ShiftOp, Mask)) {
-      if (ShAmt >= DestBitWidth)        // All zeros.
-        return ReplaceInstUsesWith(CI, Constant::getNullValue(DestTy));
-      
-      // Okay, we can shrink this.  Truncate the input, then return a new
-      // shift.
-      Value *V1 = Builder->CreateTrunc(ShiftOp, DestTy, ShiftOp->getName());
-      Value *V2 = ConstantExpr::getTrunc(ShAmtV, DestTy);
-      return BinaryOperator::CreateLShr(V1, V2);
-    }
-  }
-  
-  // Transform trunc(shl(X, C)) -> shl(trunc(X), C)
-  if (Src->hasOneUse() &&
-      match(Src, m_Shl(m_Value(ShiftOp), m_ConstantInt(ShAmtV)))) {
-    uint32_t ShAmt = ShAmtV->getLimitedValue(SrcBitWidth);
-    if (ShAmt >= DestBitWidth)        // All zeros.
-      return ReplaceInstUsesWith(CI, Constant::getNullValue(DestTy));
-      
-    // Okay, we can shrink this.  Truncate the input, then return a new
-    // shift.
-    Value *V1 = Builder->CreateTrunc(ShiftOp, DestTy, ShiftOp->getName());
-    Value *V2 = ConstantExpr::getTrunc(ShAmtV, DestTy);
-    return BinaryOperator::CreateShl(V1, V2);
-  }
-
   return 0;
 }
 

Modified: llvm/trunk/test/Transforms/InstCombine/bswap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bswap.ll?rev=92788&r1=92787&r2=92788&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/bswap.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/bswap.ll Tue Jan  5 16:01:41 2010
@@ -1,3 +1,5 @@
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+
 ; RUN: opt < %s -instcombine -S | \
 ; RUN:    grep {call.*llvm.bswap} | count 6
 





More information about the llvm-commits mailing list