From: Nikita Popov Date: Sat, 23 Mar 2019 12:48:54 +0000 (+0000) Subject: [LowerSwitch] Use ConstantRange::fromKnownBits(); NFC X-Git-Tag: llvmorg-10-init~9320 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0125e4484e263e513af266516f011a9d6dfd157f;p=platform%2Fupstream%2Fllvm.git [LowerSwitch] Use ConstantRange::fromKnownBits(); NFC Using an unsigned range to stay NFC, but a signed range would really be more useful here. llvm-svn: 356831 --- diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index 08db63e..3c973e7 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -436,14 +436,6 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) { return NumSimpleCases; } -static ConstantRange getConstantRangeFromKnownBits(const KnownBits &Known) { - APInt Lower = Known.One; - APInt Upper = ~Known.Zero + 1; - if (Upper == Lower) - return ConstantRange(Known.getBitWidth(), /*isFullSet=*/true); - return ConstantRange(Lower, Upper); -} - /// Replace the specified switch instruction with a sequence of chained if-then /// insts in a balanced binary search. void LowerSwitch::processSwitchInst(SwitchInst *SI, @@ -501,7 +493,9 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI, // switch, while LowerSwitch only needs to call LVI once per switch. const DataLayout &DL = F->getParent()->getDataLayout(); KnownBits Known = computeKnownBits(Val, DL, /*Depth=*/0, AC, SI); - ConstantRange KnownBitsRange = getConstantRangeFromKnownBits(Known); + // TODO Shouldn't this create a signed range? + ConstantRange KnownBitsRange = + ConstantRange::fromKnownBits(Known, /*ForSigned=*/false); const ConstantRange LVIRange = LVI->getConstantRange(Val, OrigBlock, SI); ConstantRange ValRange = KnownBitsRange.intersectWith(LVIRange); // We delegate removal of unreachable non-default cases to other passes. In