From 55fc8c4c39005424f72968e8a3e9355d9611945c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 1 Apr 2007 20:57:36 +0000 Subject: [PATCH] simplify this code, make it work for ap ints git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35561 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index b3679a90d02..87f96674285 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3594,14 +3594,14 @@ static bool CollectBSwapParts(Value *V, SmallVector &ByteValues) { /// 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(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 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 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) { 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); }