Skip to content

Commit

Permalink
Merged master:7a4e26adc8c2 into amd-gfx:d26dce3aa605
Browse files Browse the repository at this point in the history
Local branch amd-gfx d26dce3 Merged master:3137c299269d into amd-gfx:b4105232fca7
Remote branch master 7a4e26a [SelectionDAG] Fix miscompile bug in expandFunnelShift
  • Loading branch information
Sw authored and Sw committed Aug 24, 2020
2 parents d26dce3 + 7a4e26a commit 705782c
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 122 deletions.
39 changes: 32 additions & 7 deletions llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,27 @@ class Type;
/// This is the base class for unary cast operator classes.
class SCEVCastExpr : public SCEV {
protected:
const SCEV *Op;
const SCEV *const Op;
Type *Ty;

SCEVCastExpr(const FoldingSetNodeIDRef ID,
unsigned SCEVTy, const SCEV *op, Type *ty);

public:
const SCEV *getOperand() const { return Op; }
const SCEV *getOperand(unsigned i) const {
assert(i == 0 && "Operand index out of range!");
return Op;
}
using op_iterator = const SCEV *const *;
using op_range = iterator_range<op_iterator>;

op_iterator op_begin() const { return &Op; }
op_iterator op_end() const { return &Op + 1; }
op_range operands() const {
return make_range(op_begin(), op_end());
}
size_t getNumOperands() const { return 1; }
Type *getType() const { return Ty; }

/// Methods for support type inquiry through isa, cast, and dyn_cast:
Expand Down Expand Up @@ -263,16 +276,28 @@ class Type;
class SCEVUDivExpr : public SCEV {
friend class ScalarEvolution;

const SCEV *LHS;
const SCEV *RHS;
std::array<const SCEV*, 2> Operands;

SCEVUDivExpr(const FoldingSetNodeIDRef ID, const SCEV *lhs, const SCEV *rhs)
: SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs})), LHS(lhs),
RHS(rhs) {}
: SCEV(ID, scUDivExpr, computeExpressionSize({lhs, rhs})) {
Operands[0] = lhs;
Operands[1] = rhs;
}

public:
const SCEV *getLHS() const { return LHS; }
const SCEV *getRHS() const { return RHS; }
const SCEV *getLHS() const { return Operands[0]; }
const SCEV *getRHS() const { return Operands[1]; }
size_t getNumOperands() const { return 2; }
const SCEV *getOperand(unsigned i) const {
assert((i == 0 || i == 1) && "Operand index out of range!");
return i == 0 ? getLHS() : getRHS();
}

using op_iterator = const SCEV *const *;
using op_range = iterator_range<op_iterator>;
op_range operands() const {
return make_range(Operands.begin(), Operands.end());
}

Type *getType() const {
// In most cases the types of LHS and RHS will be the same, but in some
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/LiveDebugVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ LiveDebugVariables::LiveDebugVariables() : MachineFunctionPass(ID) {

enum : unsigned { UndefLocNo = ~0U };

namespace {
/// Describes a debug variable value by location number and expression along
/// with some flags about the original usage of the location.
class DbgVariableValue {
Expand Down Expand Up @@ -136,6 +137,7 @@ class DbgVariableValue {
unsigned WasIndirect : 1;
const DIExpression *Expression = nullptr;
};
} // namespace

/// Map of where a user value is live to that value.
using LocMap = IntervalMap<SlotIndex, DbgVariableValue, 4>;
Expand Down
16 changes: 2 additions & 14 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6140,7 +6140,7 @@ bool TargetLowering::expandMUL(SDNode *N, SDValue &Lo, SDValue &Hi, EVT HiLoVT,
}

// Check that (every element of) Z is undef or not an exact multiple of BW.
static bool isNonZeroModBitWidth(SDValue Z, unsigned BW) {
static bool isNonZeroModBitWidthOrUndef(SDValue Z, unsigned BW) {
return ISD::matchUnaryPredicate(
Z,
[=](ConstantSDNode *C) { return !C || C->getAPIntValue().urem(BW) != 0; },
Expand All @@ -6167,21 +6167,9 @@ bool TargetLowering::expandFunnelShift(SDNode *Node, SDValue &Result,

EVT ShVT = Z.getValueType();

assert(isPowerOf2_32(BW) && "Expecting the type bitwidth to be a power of 2");

// If a funnel shift in the other direction is more supported, use it.
unsigned RevOpcode = IsFSHL ? ISD::FSHR : ISD::FSHL;
if (!isOperationLegalOrCustom(Node->getOpcode(), VT) &&
isOperationLegalOrCustom(RevOpcode, VT)) {
SDValue Zero = DAG.getConstant(0, DL, ShVT);
SDValue Sub = DAG.getNode(ISD::SUB, DL, ShVT, Zero, Z);
Result = DAG.getNode(RevOpcode, DL, VT, X, Y, Sub);
return true;
}

SDValue ShX, ShY;
SDValue ShAmt, InvShAmt;
if (isNonZeroModBitWidth(Z, BW)) {
if (isNonZeroModBitWidthOrUndef(Z, BW)) {
// fshl: X << C | Y >> (BW - C)
// fshr: X << (BW - C) | Y >> C
// where C = Z % BW is not zero
Expand Down
Loading

0 comments on commit 705782c

Please sign in to comment.