From 50a281a871ee64ad76c6c44f4b60b8d47f88f4c3 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 2 Apr 2011 18:50:58 +0000 Subject: While SimplifyDemandedBits constant folds this, we can't rely on it here. It's possible to craft an input that hits the recursion limits in a way that SimplifyDemandedBits doesn't simplify the icmp but ComputeMaskedBits can infer which bits are zero. No test case as it depends on too many other things. Fixes PR9609. llvm-svn: 128777 --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 32ab123f103..6f70de86576 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -913,8 +913,13 @@ Instruction *InstCombiner::transformSExtICmp(ICmpInst *ICI, Instruction &CI) { if (KnownZeroMask.isPowerOf2()) { Value *In = ICI->getOperand(0); - assert((Op1C->isZero() || Op1C->getValue() == KnownZeroMask) && - "Constant icmp not folded?"); + // If the icmp tests for a known zero bit we can constant fold it. + if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) { + Value *V = Pred == ICmpInst::ICMP_NE ? + ConstantInt::getAllOnesValue(CI.getType()) : + ConstantInt::getNullValue(CI.getType()); + return ReplaceInstUsesWith(CI, V); + } if (!Op1C->isZero() == (Pred == ICmpInst::ICMP_NE)) { // sext ((x & 2^n) == 0) -> (x >> n) - 1 -- cgit v1.2.3