[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Sun Apr 1 13:57:54 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.717 -> 1.718
---
Log message:

simplify this code, make it work for ap ints


---
Diffs of the changes:  (+6 -17)

 InstructionCombining.cpp |   23 ++++++-----------------
 1 files changed, 6 insertions(+), 17 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.717 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.718
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.717	Sun Apr  1 12:13:37 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sun Apr  1 15:57:36 2007
@@ -3594,14 +3594,14 @@
 /// MatchBSwap - Given an OR instruction, check to see if this is a bswap idiom.
 /// If so, insert the new bswap intrinsic and return it.
 Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) {
-  // We cannot bswap one byte.
-  if (I.getType() == Type::Int8Ty)
-    return 0;
+  const IntegerType *ITy = dyn_cast<IntegerType>(I.getType());
+  if (!ITy || ITy->getBitWidth() % 16) 
+    return 0;   // Can only bswap pairs of bytes.  Can't do vectors.
   
   /// ByteValues - For each byte of the result, we keep track of which value
   /// defines each byte.
   SmallVector<Value*, 8> ByteValues;
-  ByteValues.resize(TD->getTypeSize(I.getType()));
+  ByteValues.resize(ITy->getBitWidth()/8);
     
   // Try to find all the pieces corresponding to the bswap.
   if (CollectBSwapParts(I.getOperand(0), ByteValues) ||
@@ -3616,20 +3616,9 @@
   for (unsigned i = 1, e = ByteValues.size(); i != e; ++i)
     if (ByteValues[i] != V)
       return 0;
-    
-  // If they do then *success* we can turn this into a bswap.  Figure out what
-  // bswap to make it into.
+  const Type *Tys[] = { ITy, ITy };
   Module *M = I.getParent()->getParent()->getParent();
-  const char *FnName = 0;
-  if (I.getType() == Type::Int16Ty)
-    FnName = "llvm.bswap.i16.i16";
-  else if (I.getType() == Type::Int32Ty)
-    FnName = "llvm.bswap.i32.i32";
-  else if (I.getType() == Type::Int64Ty)
-    FnName = "llvm.bswap.i64.i64";
-  else
-    assert(0 && "Unknown integer type!");
-  Constant *F = M->getOrInsertFunction(FnName, I.getType(), I.getType(), NULL);
+  Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 2);
   return new CallInst(F, V);
 }
 






More information about the llvm-commits mailing list