Skip to content

Commit

Permalink
[SelectionDAG] Rework lowerRangeToAssertZExt
Browse files Browse the repository at this point in the history
Utilize ConstantRange to make it easier to interpret range metadata.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291211 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Jan 6, 2017
1 parent fd456e3 commit 9ec4de5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/WinEHFuncInfo.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
Expand Down Expand Up @@ -7339,19 +7340,23 @@ SDValue SelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
if (!Range)
return Op;

Constant *Lo = cast<ConstantAsMetadata>(Range->getOperand(0))->getValue();
if (!Lo->isNullValue())
ConstantRange CR = getConstantRangeFromMetadata(*Range);
if (CR.isFullSet() || CR.isEmptySet() || CR.isWrappedSet())
return Op;

Constant *Hi = cast<ConstantAsMetadata>(Range->getOperand(1))->getValue();
unsigned Bits = cast<ConstantInt>(Hi)->getValue().ceilLogBase2();
APInt Lo = CR.getUnsignedMin();
if (!Lo.isMinValue())
return Op;

APInt Hi = CR.getUnsignedMax();
unsigned Bits = Hi.getActiveBits();

EVT SmallVT = EVT::getIntegerVT(*DAG.getContext(), Bits);

SDLoc SL = getCurSDLoc();

SDValue ZExt = DAG.getNode(ISD::AssertZext, SL, Op.getValueType(),
Op, DAG.getValueType(SmallVT));
SDValue ZExt = DAG.getNode(ISD::AssertZext, SL, Op.getValueType(), Op,
DAG.getValueType(SmallVT));
unsigned NumVals = Op.getNode()->getNumValues();
if (NumVals == 1)
return ZExt;
Expand Down

0 comments on commit 9ec4de5

Please sign in to comment.