[llvm] r185954 - ValueTracking: Fix bugs in isKnownToBeAPowerOfTwo

Hal Finkel hfinkel at anl.gov
Wed Jul 10 10:28:42 PDT 2013


----- Original Message -----
> Author: majnemer
> Date: Tue Jul  9 13:11:10 2013
> New Revision: 185954
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=185954&view=rev
> Log:
> ValueTracking: Fix bugs in isKnownToBeAPowerOfTwo
> 
> (add nsw x, (and x, y)) isn't a power of two if x is zero, it's zero

I don't think that this requires nsw:

cvc4 1.2 assertions:off
CVC4> OPTION "produce-models";
CVC4> x, y : BITVECTOR(32);
CVC4> ISPOW2 : BITVECTOR(32) -> BOOLEAN = LAMBDA(x : BITVECTOR(32)): BVPLUS(32, x, 0hexffffffff) & x = 0hex00000000;
CVC4> ASSERT ISPOW2(x);
CVC4> QUERY(ISPOW2(BVPLUS(32, x, x & y)));
valid

> (add nsw x, (xor x, y)) isn't a power of two if y has bits set that
> aren't set in x

And neither does this:

cvc4 1.2 assertions:off
CVC4> OPTION "produce-models";
CVC4> x, y : BITVECTOR(32);
CVC4> ISPOW2 : BITVECTOR(32) -> BOOLEAN = LAMBDA(x : BITVECTOR(32)): BVPLUS(32, x, 0hexffffffff) & x = 0hex00000000;
CVC4> ASSERT ISPOW2(x);
CVC4> ASSERT(~x & y = 0hex00000000);
CVC4> QUERY(ISPOW2(BVPLUS(32, x, BVXOR(x,y))));
valid

 -Hal

> 
> Modified:
>     llvm/trunk/lib/Analysis/ValueTracking.cpp
>     llvm/trunk/test/Transforms/InstCombine/rem.ll
> 
> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=185954&r1=185953&r2=185954&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Jul  9 13:11:10
> 2013
> @@ -861,16 +861,14 @@ bool llvm::isKnownToBeAPowerOfTwo(Value
>          // Adding a power of two to the same power of two is a power
>          of two or
>          // zero.
>          if (BinaryOperator *XBO = dyn_cast<BinaryOperator>(X))
> -          if (XBO->getOpcode() == Instruction::And ||
> -              XBO->getOpcode() == Instruction::Xor)
> +          if (XBO->getOpcode() == Instruction::And)
>              if (XBO->getOperand(0) == Y || XBO->getOperand(1) == Y)
> -              if (isKnownToBeAPowerOfTwo(Y, /*OrZero*/true, Depth))
> +              if (isKnownToBeAPowerOfTwo(Y, OrZero, Depth))
>                  return true;
>          if (BinaryOperator *YBO = dyn_cast<BinaryOperator>(Y))
> -          if (YBO->getOpcode() == Instruction::And ||
> -              YBO->getOpcode() == Instruction::Xor)
> +          if (YBO->getOpcode() == Instruction::And)
>              if (YBO->getOperand(0) == X || YBO->getOperand(1) == X)
> -              if (isKnownToBeAPowerOfTwo(X, /*OrZero*/true, Depth))
> +              if (isKnownToBeAPowerOfTwo(X, OrZero, Depth))
>                  return true;
>        }
>  
> 
> Modified: llvm/trunk/test/Transforms/InstCombine/rem.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/rem.ll?rev=185954&r1=185953&r2=185954&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/rem.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/rem.ll Tue Jul  9 13:11:10
> 2013
> @@ -163,18 +163,3 @@ define i32 @test16(i32 %x, i32 %y) {
>  	%rem = urem i32 %x, %add
>  	ret i32 %rem
>  }
> -
> -define i32 @test17(i16 %x, i32 %y) {
> -; CHECK: @test17
> -; CHECK-NEXT: [[AND:%.*]] = and i16 %x, 4
> -; CHECK-NEXT: [[EXT:%.*]] = zext i16 [[AND]] to i32
> -; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[EXT]], 3
> -; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[SHL]], 63
> -; CHECK-NEXT: [[REM:%.*]] = and i32 [[XOR]], %y
> -; CHECK-NEXT: ret i32 [[REM]]
> -	%1 = and i16 %x, 4
> -	%2 = icmp ne i16 %1, 0
> -	%3 = select i1 %2, i32 32, i32 64
> -	%4 = urem i32 %y, %3
> -	ret i32 %4
> -}
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list