[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
clattner at apple.com
Wed Mar 21 17:00:59 PDT 2007
> For PR1248: http://llvm.org/PR1248 :
> * Fix some indentation and comments in InsertRangeTest
> * Add an "IsSigned" parameter to AddWithOverflow and make it handle
> signed
> additions. Also, APIntify this function so it works with any
> bitwidth.
> * For the icmp pred ([us]div %X, C1), C2 transforms, exit early if the
> div instruction's RHS is zero.
> * Finally, for icmp pred (sdiv %X, C1), -C2, fix an off-by-one
> error. The
> HiBound needs to be incremented in order to get the range test
> correct.
Thanks Reid, testcase please!
> /// AddWithOverflow - Compute Result = In1+In2, returning true if
> the result
> /// overflowed for this type.
> static bool AddWithOverflow(ConstantInt *&Result, ConstantInt *In1,
> - ConstantInt *In2) {
> + ConstantInt *In2, bool IsSigned =
> false) {
> Result = cast<ConstantInt>(ConstantExpr::getAdd(In1, In2));
>
> - return cast<ConstantInt>(Result)->getZExtValue() <
> - cast<ConstantInt>(In1)->getZExtValue();
> + if (IsSigned)
> + if (In2->getValue().isNegative())
> + return Result->getValue().sgt(In1->getValue());
> + else
> + return Result->getValue().slt(In1->getValue());
I don't understand this logic. Shouldn't it always be slt?
-Chris
More information about the llvm-commits
mailing list