Index: llvm/trunk/lib/Analysis/AssumptionCache.cpp =================================================================== --- llvm/trunk/lib/Analysis/AssumptionCache.cpp +++ llvm/trunk/lib/Analysis/AssumptionCache.cpp @@ -47,9 +47,11 @@ } else if (auto *I = dyn_cast(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(Op) || isa(Op)) Affected.push_back(Op); } Index: llvm/trunk/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/trunk/lib/Analysis/ValueTracking.cpp +++ llvm/trunk/lib/Analysis/ValueTracking.cpp @@ -553,6 +553,13 @@ 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) Index: llvm/trunk/test/Transforms/InstCombine/assume.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/assume.ll +++ llvm/trunk/test/Transforms/InstCombine/assume.ll @@ -176,13 +176,13 @@ 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) Index: llvm/trunk/test/Transforms/InstCombine/select.ll =================================================================== --- llvm/trunk/test/Transforms/InstCombine/select.ll +++ llvm/trunk/test/Transforms/InstCombine/select.ll @@ -1344,14 +1344,13 @@ 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)