[llvm] r219586 - APSInt: Simplify code to reduce the number of copies. No functionality change.

Benjamin Kramer benny.kra at gmail.com
Tue Oct 14 10:32:38 PDT 2014


On 14.10.2014, at 19:28, David Blaikie <dblaikie at gmail.com> wrote:

> 
> 
> On Sun, Oct 12, 2014 at 8:36 AM, Benjamin Kramer <benny.kra at googlemail.com> wrote:
> Author: d0k
> Date: Sun Oct 12 10:36:31 2014
> New Revision: 219586
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=219586&view=rev
> Log:
> APSInt: Simplify code to reduce the number of copies. No functionality change.
> 
> Modified:
>     llvm/trunk/include/llvm/ADT/APSInt.h
> 
> Modified: llvm/trunk/include/llvm/ADT/APSInt.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=219586&r1=219585&r2=219586&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/APSInt.h (original)
> +++ llvm/trunk/include/llvm/ADT/APSInt.h Sun Oct 12 10:36:31 2014
> @@ -269,19 +269,15 @@ public:
>      else if (I2.getBitWidth() > I1.getBitWidth())
>        return isSameValue(I1.extend(I2.getBitWidth()), I2);
> 
> -    // We have a signedness mismatch. Turn the signed value into an unsigned
> -    // value.
> -    if (I1.isSigned()) {
> -      if (I1.isNegative())
> -        return false;
> +    assert(I1.isSigned() != I2.isSigned());
> 
> -      return APSInt(I1, true) == I2;
> -    }
> -
> -    if (I2.isNegative())
> +    // We have a signedness mismatch. Check for negative values and do an
> +    // unsigned compare if signs match.
> +    if ((I1.isSigned() && I1.isNegative()) ||
> +        (!I1.isSigned() && I2.isNegative()))
>        return false;
> 
> -    return I1 == APSInt(I2, true);
> +    return I1.eq(I2);
> 
> Hmm, is this different from l1 == l2? (that seems like a dangerously subtle API if that's the case)

APSInt::operator== asserts if signedness doesn't match and then calls eq. That method is inherited from APInt. It's a bit unexpected but doesn't seem dangerous to me.

- Ben

>  
>    }
> 
>    /// Profile - Used to insert APSInt objects, or objects that contain APSInt
> 
> 
> _______________________________________________
> 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