Index: lib/Analysis/ValueTracking.cpp =================================================================== --- lib/Analysis/ValueTracking.cpp +++ lib/Analysis/ValueTracking.cpp @@ -1071,12 +1071,16 @@ // Check whether there's a dominating condition which implies something about // this value at the given context. if (EnableDomConditions && Depth <= DomConditionsMaxDepth) + // FIXME: this call may overwrite the known bits computed from assumes. computeKnownBitsFromDominatingCondition(V, KnownZero, KnownOne, DL, Depth, Q); Operator *I = dyn_cast(V); if (!I) return; + // Save KnownZero and KnownOne so that they won't be overwritten by the + // following computeKnownBits calls. + APInt SavedKnownZero(KnownZero), SavedKnownOne(KnownOne); APInt KnownZero2(KnownZero), KnownOne2(KnownOne); switch (I->getOpcode()) { default: break; @@ -1523,6 +1527,8 @@ } } } + KnownZero |= SavedKnownZero; + KnownOne |= SavedKnownOne; assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); } Index: test/Analysis/ValueTracking/assume.ll =================================================================== --- /dev/null +++ test/Analysis/ValueTracking/assume.ll @@ -0,0 +1,14 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +define i32 @assume_add(i32 %a, i32 %b) { +; CHECK-LABEL: @assume_add( + %1 = add i32 %a, %b + %last_two_digits = and i32 %1, 3 + %2 = icmp eq i32 %last_two_digits, 0 + call void @llvm.assume(i1 %2) + %3 = add i32 %1, 3 +; CHECK: %3 = or i32 %1, 3 + ret i32 %3 +} + +declare void @llvm.assume(i1)