[ValueTracking] recognize a 'not' of an assumed condition as false

Also, add the corresponding match to the AssumptionCache's 'Affected Values' list.

Differential Revision: https://reviews.llvm.org/D28485

llvm-svn: 292239
This commit is contained in:
Sanjay Patel 2017-01-17 18:15:49 +00:00
parent 5ce5bd5531
commit d9256d18d9
4 changed files with 16 additions and 8 deletions

View File

@ -47,9 +47,11 @@ void AssumptionCache::updateAffectedValues(CallInst *CI) {
} else if (auto *I = dyn_cast<Instruction>(V)) {
Affected.push_back(I);
if (I->getOpcode() == Instruction::BitCast ||
I->getOpcode() == Instruction::PtrToInt) {
auto *Op = I->getOperand(0);
// Peek through unary operators to find the source of the condition.
Value *Op;
if (match(I, m_BitCast(m_Value(Op))) ||
match(I, m_PtrToInt(m_Value(Op))) ||
match(I, m_Not(m_Value(Op)))) {
if (isa<Instruction>(Op) || isa<Argument>(Op))
Affected.push_back(Op);
}

View File

@ -553,6 +553,13 @@ static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero,
KnownOne.setAllBits();
return;
}
if (match(Arg, m_Not(m_Specific(V))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
assert(BitWidth == 1 && "assume operand is not i1?");
KnownZero.setAllBits();
KnownOne.clearAllBits();
return;
}
// The remaining tests are all recursive, so bail out if we hit the limit.
if (Depth == MaxDepth)

View File

@ -176,13 +176,13 @@ define i32 @icmp2(i32 %a) #0 {
ret i32 %lnot.ext
}
; FIXME: If the 'not' of a condition is known true, then the condition must be false.
; If the 'not' of a condition is known true, then the condition must be false.
define i1 @assume_not(i1 %cond) {
; CHECK-LABEL: @assume_not(
; CHECK-NEXT: [[NOTCOND:%.*]] = xor i1 [[COND:%.*]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[NOTCOND]])
; CHECK-NEXT: ret i1 [[COND]]
; CHECK-NEXT: ret i1 false
;
%notcond = xor i1 %cond, true
call void @llvm.assume(i1 %notcond)

View File

@ -1344,14 +1344,13 @@ define i8 @assume_cond_true(i1 %cond, i8 %x, i8 %y) {
ret i8 %sel
}
; FIXME: computeKnownBitsFromAssume() should understand the 'not' of an assumed condition.
; computeKnownBitsFromAssume() understands the 'not' of an assumed condition.
define i8 @assume_cond_false(i1 %cond, i8 %x, i8 %y) {
; CHECK-LABEL: @assume_cond_false(
; CHECK-NEXT: [[NOTCOND:%.*]] = xor i1 %cond, true
; CHECK-NEXT: call void @llvm.assume(i1 [[NOTCOND]])
; CHECK-NEXT: [[SEL:%.*]] = select i1 %cond, i8 %x, i8 %y
; CHECK-NEXT: ret i8 [[SEL]]
; CHECK-NEXT: ret i8 %y
;
%notcond = xor i1 %cond, true
call void @llvm.assume(i1 %notcond)