[llvm-commits] [llvm] r85478 - /llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
Victor Hernandez
vhernandez at apple.com
Thu Oct 29 17:28:17 PDT 2009
Duncan,
Here's my patch to get rid of doubles, how does it look?
Index: lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- lib/Analysis/MemoryBuiltins.cpp (revision 85528)
+++ lib/Analysis/MemoryBuiltins.cpp (working copy)
@@ -158,13 +158,19 @@
if (Opcode == Instruction::Shl) {
ConstantInt* Op1Int = dyn_cast<ConstantInt>(Op1);
if (!Op1Int) return NULL;
- Value* Op1Pow = ConstantInt::get(Op1->getType(),
- pow(2.0, (double) Op1Int-
>getZExtValue()));
+
+ unsigned Op1BitWidth = Op1->getType()->getPrimitiveSizeInBits();
+ // check for overflow
+ if (Op1Int->getZExtValue() > Op1BitWidth)
+ return NULL;
+
+ Value* Op1Pow = ConstantInt::get(Context,
+ APInt(Op1BitWidth, 1, false) << Op1Int-
>getValue());
if (Op0 == ElementSize || (FoldedElementSize && Op0 ==
FoldedElementSize))
// ArraySize << log2(ElementSize)
return Op1Pow;
if (Op1Pow == ElementSize ||
- (FoldedElementSize && Op1Pow == FoldedElementSize))
+ (FoldedElementSize && Op1Pow == FoldedElementSize))
// ElementSize << log2(ArraySize)
return Op0;
}
thanks,
Victor
On Oct 29, 2009, at 1:26 AM, Duncan Sands wrote:
> Hi,
>
>> ConstantInt* Op1Int = dyn_cast<ConstantInt>(Op1);
>> if (!Op1Int) return NULL;
>> Value* Op1Pow = ConstantInt::get(Op1->getType(),
>> - pow(2, Op1Int->getZExtValue
>> ()));
>> + pow((double) 2, (double)
>> Op1Int->getZExtValue()));
>
> this is an integer power: 2 to the power of Op1Int. This shouldn't
> be done like
> this at all! It's just a shift left for heavens sake - why the
> doubles?! It
> can other be done in uint64_t, or using the APInt shift methods.
>
> /me makes note to self to audit this code for other monstrosities.
>
> Ciao,
>
> Duncan.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list