diff --git a/lib/Infer/Pruning.cpp b/lib/Infer/Pruning.cpp index b5e55ff7c..ba560cc39 100644 --- a/lib/Infer/Pruning.cpp +++ b/lib/Infer/Pruning.cpp @@ -414,7 +414,12 @@ bool PruningManager::isInfeasible(souper::Inst *RHS, } else { auto RHSV = ConcreteInterpreters[I].evaluateInst(RHS); if (RHSV.hasValue()) { - if (Val != RHSV.getValue()) { + auto RVal = RHSV.getValue(); + if (SC.LHS->DemandedBits != 0) { + Val &= SC.LHS->DemandedBits; + RVal &= SC.LHS->DemandedBits; + } + if (Val != RVal) { if (StatsLevel > 2) { llvm::errs() << " RHS value = " << RHSV.getValue() << "\n"; llvm::errs() << " pruned using concrete interpreter!\n"; diff --git a/test/Infer/pruning/dontprune.opt b/test/Infer/pruning/dontprune.opt new file mode 100644 index 000000000..c2010064f --- /dev/null +++ b/test/Infer/pruning/dontprune.opt @@ -0,0 +1,18 @@ +; REQUIRES: synthesis + +; RUN: %souper-check -try-dataflow-pruning %s > %t +; RUN: %FileCheck %s < %t + +; CHECK: Pruning failed + +%0 = block 2 +%1:i64 = var +%2:i64 = lshr %1, 16:i64 +%3:i64 = var +%4:i64 = lshr %3, 16:i64 +%5:i64 = phi %0, %2, %4 +%6:i16 = trunc %5 +%7:i32 = zext %6 +infer %7 (demandedBits=00000000000000001111111100000000) +%8:i32 = trunc %5 +result %8