From a92b3c914ebb356aec22c978eae9fa9543fa62e6 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 9 Jul 2013 18:11:10 +0000 Subject: [PATCH] ValueTracking: Fix bugs in isKnownToBeAPowerOfTwo (add nsw x, (and x, y)) isn't a power of two if x is zero, it's zero (add nsw x, (xor x, y)) isn't a power of two if y has bits set that aren't set in x llvm-svn: 185954 --- llvm/lib/Analysis/ValueTracking.cpp | 10 ++++------ llvm/test/Transforms/InstCombine/rem.ll | 15 --------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index b3693b35452e..1b20a25ef261 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -861,16 +861,14 @@ bool llvm::isKnownToBeAPowerOfTwo(Value *V, bool OrZero, unsigned Depth) { // Adding a power of two to the same power of two is a power of two or // zero. if (BinaryOperator *XBO = dyn_cast(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(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; } diff --git a/llvm/test/Transforms/InstCombine/rem.ll b/llvm/test/Transforms/InstCombine/rem.ll index 2b49385b9227..808d51eba1d2 100644 --- a/llvm/test/Transforms/InstCombine/rem.ll +++ b/llvm/test/Transforms/InstCombine/rem.ll @@ -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 -}