Skip to content

Commit

Permalink
Merged master:43df29e20622 into amd-gfx:72ec2482f727
Browse files Browse the repository at this point in the history
Local branch amd-gfx 72ec248 Merge master:5e312e004197 into amd-gfx
Remote branch master 43df29e [VE] Optimize address calculation
  • Loading branch information
Sw authored and Sw committed Nov 6, 2020
2 parents 72ec248 + 43df29e commit 3a0ab31
Show file tree
Hide file tree
Showing 20 changed files with 497 additions and 149 deletions.
16 changes: 13 additions & 3 deletions clang/lib/Format/BreakableToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn,
MaxSplitBytes += BytesInChar;
}

// In JavaScript, some @tags can be followed by {, and machinery that parses
// these comments will fail to understand the comment if followed by a line
// break. So avoid ever breaking before a {.
if (Style.Language == FormatStyle::LK_JavaScript) {
StringRef::size_type SpaceOffset =
Text.find_first_of(Blanks, MaxSplitBytes);
if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
Text[SpaceOffset + 1] == '{') {
MaxSplitBytes = SpaceOffset + 1;
}
}

StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);

static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
Expand All @@ -94,9 +106,7 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn,
// as a numbered list, which would prevent re-flowing in subsequent passes.
if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
// In JavaScript, some @tags can be followed by {, and machinery that parses
// these comments will fail to understand the comment if followed by a line
// break. So avoid ever breaking before a {.
// Avoid ever breaking before a { in JavaScript.
else if (Style.Language == FormatStyle::LK_JavaScript &&
SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
Expand Down
10 changes: 10 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,16 @@ TEST_F(FormatTestJS, JSDocAnnotations) {
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
// cases where '{' is around the column limit
for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
verifyFormat("/**\n"
" * @param {type}\n"
" */",
"/**\n"
" * @param {type}\n"
" */",
getGoogleJSStyleWithColumns(ColumnLimit));
}
verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n"
" */",
Expand Down
38 changes: 36 additions & 2 deletions llvm/include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,19 @@ class CmpInst : public Instruction {
/// Determine if this CmpInst is commutative.
bool isCommutative() const;

/// This is just a convenience that dispatches to the subclasses.
/// Determine if this is an equals/not equals predicate.
bool isEquality() const;
/// This is a static version that you can use without an instruction
/// available.
static bool isEquality(Predicate pred);

/// Determine if this is an equals/not equals predicate.
bool isEquality() const { return isEquality(getPredicate()); }

/// Return true if the predicate is relational (not EQ or NE).
static bool isRelational(Predicate P) { return !isEquality(P); }

/// Return true if the predicate is relational (not EQ or NE).
bool isRelational() const { return !isEquality(); }

/// @returns true if the comparison is signed, false otherwise.
/// Determine if this instruction is using a signed comparison.
Expand All @@ -920,6 +930,30 @@ class CmpInst : public Instruction {
return getSignedPredicate(getPredicate());
}

/// For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert
/// @returns the unsigned version of the signed predicate pred.
static Predicate getUnsignedPredicate(Predicate pred);

/// For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert
/// @returns the unsigned version of the predicate for this instruction (which
/// has to be an signed predicate).
/// return the unsigned version of a predicate
Predicate getUnsignedPredicate() {
return getUnsignedPredicate(getPredicate());
}

/// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
/// @returns the unsigned version of the signed predicate pred or
/// the signed version of the signed predicate pred.
static Predicate getFlippedSignednessPredicate(Predicate pred);

/// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
/// @returns the unsigned version of the signed predicate pred or
/// the signed version of the signed predicate pred.
Predicate getFlippedSignednessPredicate() {
return getFlippedSignednessPredicate(getPredicate());
}

/// This is just a convenience.
/// Determine if this is true when both operands are the same.
bool isTrueWhenEqual() const {
Expand Down
23 changes: 22 additions & 1 deletion llvm/include/llvm/Support/TypeSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class UnivariateLinearPolyBase {
ScalarTy Value; // The value at the univeriate dimension.
unsigned UnivariateDim; // The univeriate dimension.

UnivariateLinearPolyBase(ScalarTy &Val, unsigned UnivariateDim)
UnivariateLinearPolyBase(ScalarTy Val, unsigned UnivariateDim)
: Value(Val), UnivariateDim(UnivariateDim) {
assert(UnivariateDim < Dimensions && "Dimension out of range");
}
Expand Down Expand Up @@ -229,6 +229,18 @@ class UnivariateLinearPolyBase {
ScalarTy getValue(unsigned Dim) const {
return Dim == UnivariateDim ? Value : 0;
}

/// Add \p RHS to the value at the univariate dimension.
LeafTy getWithIncrement(ScalarTy RHS) {
return static_cast<LeafTy>(
UnivariateLinearPolyBase(Value + RHS, UnivariateDim));
}

/// Subtract \p RHS from the value at the univariate dimension.
LeafTy getWithDecrement(ScalarTy RHS) {
return static_cast<LeafTy>(
UnivariateLinearPolyBase(Value - RHS, UnivariateDim));
}
};


Expand All @@ -247,6 +259,11 @@ class UnivariateLinearPolyBase {
/// fixed-sized or it is scalable-sized, but it cannot be both.
template <typename LeafTy>
class LinearPolySize : public UnivariateLinearPolyBase<LeafTy> {
// Make the parent class a friend, so that it can access the protected
// conversion/copy-constructor for UnivariatePolyBase<LeafTy> ->
// LinearPolySize<LeafTy>.
friend class UnivariateLinearPolyBase<LeafTy>;

public:
using ScalarTy = typename UnivariateLinearPolyBase<LeafTy>::ScalarTy;
enum Dims : unsigned { FixedDim = 0, ScalableDim = 1 };
Expand All @@ -255,7 +272,11 @@ class LinearPolySize : public UnivariateLinearPolyBase<LeafTy> {
LinearPolySize(ScalarTy MinVal, Dims D)
: UnivariateLinearPolyBase<LeafTy>(MinVal, D) {}

LinearPolySize(const UnivariateLinearPolyBase<LeafTy> &V)
: UnivariateLinearPolyBase<LeafTy>(V) {}

public:

static LeafTy getFixed(ScalarTy MinVal) {
return static_cast<LeafTy>(LinearPolySize(MinVal, FixedDim));
}
Expand Down
41 changes: 36 additions & 5 deletions llvm/lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3682,10 +3682,12 @@ bool CmpInst::isCommutative() const {
return cast<FCmpInst>(this)->isCommutative();
}

bool CmpInst::isEquality() const {
if (const ICmpInst *IC = dyn_cast<ICmpInst>(this))
return IC->isEquality();
return cast<FCmpInst>(this)->isEquality();
bool CmpInst::isEquality(Predicate P) {
if (ICmpInst::isIntPredicate(P))
return ICmpInst::isEquality(P);
if (FCmpInst::isFPPredicate(P))
return FCmpInst::isEquality(P);
llvm_unreachable("Unsupported predicate kind");
}

CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
Expand Down Expand Up @@ -3847,7 +3849,7 @@ CmpInst::Predicate CmpInst::getNonStrictPredicate(Predicate pred) {
}

CmpInst::Predicate CmpInst::getSignedPredicate(Predicate pred) {
assert(CmpInst::isUnsigned(pred) && "Call only with signed predicates!");
assert(CmpInst::isUnsigned(pred) && "Call only with unsigned predicates!");

switch (pred) {
default:
Expand All @@ -3863,6 +3865,23 @@ CmpInst::Predicate CmpInst::getSignedPredicate(Predicate pred) {
}
}

CmpInst::Predicate CmpInst::getUnsignedPredicate(Predicate pred) {
assert(CmpInst::isSigned(pred) && "Call only with signed predicates!");

switch (pred) {
default:
llvm_unreachable("Unknown predicate!");
case CmpInst::ICMP_SLT:
return CmpInst::ICMP_ULT;
case CmpInst::ICMP_SLE:
return CmpInst::ICMP_ULE;
case CmpInst::ICMP_SGT:
return CmpInst::ICMP_UGT;
case CmpInst::ICMP_SGE:
return CmpInst::ICMP_UGE;
}
}

bool CmpInst::isUnsigned(Predicate predicate) {
switch (predicate) {
default: return false;
Expand All @@ -3879,6 +3898,18 @@ bool CmpInst::isSigned(Predicate predicate) {
}
}

CmpInst::Predicate CmpInst::getFlippedSignednessPredicate(Predicate pred) {
assert(CmpInst::isRelational(pred) &&
"Call only with non-equality predicates!");

if (isSigned(pred))
return getUnsignedPredicate(pred);
if (isUnsigned(pred))
return getSignedPredicate(pred);

llvm_unreachable("Unknown predicate!");
}

bool CmpInst::isOrdered(Predicate predicate) {
switch (predicate) {
default: return false;
Expand Down
18 changes: 7 additions & 11 deletions llvm/lib/Target/VE/VEISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,23 +940,19 @@ SDValue VETargetLowering::makeAddress(SDValue Op, SelectionDAG &DAG) const {
if (isa<ConstantPoolSDNode>(Op) ||
(GlobalN && GlobalN->getGlobal()->hasLocalLinkage())) {
// Create following instructions for local linkage PIC code.
// lea %s35, %gotoff_lo(.LCPI0_0)
// and %s35, %s35, (32)0
// lea.sl %s35, %gotoff_hi(.LCPI0_0)(%s35)
// adds.l %s35, %s15, %s35 ; %s15 is GOT
// FIXME: use lea.sl %s35, %gotoff_hi(.LCPI0_0)(%s35, %s15)
// lea %reg, label@gotoff_lo
// and %reg, %reg, (32)0
// lea.sl %reg, label@gotoff_hi(%reg, %got)
SDValue HiLo = makeHiLoPair(Op, VEMCExpr::VK_VE_GOTOFF_HI32,
VEMCExpr::VK_VE_GOTOFF_LO32, DAG);
SDValue GlobalBase = DAG.getNode(VEISD::GLOBAL_BASE_REG, DL, PtrVT);
return DAG.getNode(ISD::ADD, DL, PtrVT, GlobalBase, HiLo);
}
// Create following instructions for not local linkage PIC code.
// lea %s35, %got_lo(.LCPI0_0)
// and %s35, %s35, (32)0
// lea.sl %s35, %got_hi(.LCPI0_0)(%s35)
// adds.l %s35, %s15, %s35 ; %s15 is GOT
// ld %s35, (,%s35)
// FIXME: use lea.sl %s35, %gotoff_hi(.LCPI0_0)(%s35, %s15)
// lea %reg, label@got_lo
// and %reg, %reg, (32)0
// lea.sl %reg, label@got_hi(%reg)
// ld %reg, (%reg, %got)
SDValue HiLo = makeHiLoPair(Op, VEMCExpr::VK_VE_GOT_HI32,
VEMCExpr::VK_VE_GOT_LO32, DAG);
SDValue GlobalBase = DAG.getNode(VEISD::GLOBAL_BASE_REG, DL, PtrVT);
Expand Down
98 changes: 46 additions & 52 deletions llvm/lib/Target/VE/VEInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -944,23 +944,13 @@ let isReMaterializable = 1, isAsCheapAsAMove = 1,
let cx = 1 in defm LEASL : RMm<"lea.sl", 0x06, I64>;
}

// LEA basic patterns.
// Need to be defined here to prioritize LEA over ADX.
def : Pat<(iPTR ADDRrri:$addr), (LEArri MEMrri:$addr)>;
def : Pat<(iPTR ADDRrii:$addr), (LEArii MEMrii:$addr)>;
def : Pat<(add I64:$base, simm32:$disp), (LEArii $base, 0, (LO32 $disp))>;
def : Pat<(add I64:$base, lozero:$disp), (LEASLrii $base, 0, (HI32 $disp))>;

def lea_add : PatFrags<(ops node:$base, node:$idx, node:$disp),
[(add (add node:$base, node:$idx), node:$disp),
(add (add node:$base, node:$disp), node:$idx)]>;
def : Pat<(lea_add I64:$base, simm7:$idx, simm32:$disp),
(LEArii $base, (LO7 $idx), (LO32 $disp))>;
def : Pat<(lea_add I64:$base, I64:$idx, simm32:$disp),
(LEArri $base, $idx, (LO32 $disp))>;
def : Pat<(lea_add I64:$base, simm7:$idx, lozero:$disp),
(LEASLrii $base, (LO7 $idx), (HI32 $disp))>;
def : Pat<(lea_add I64:$base, I64:$idx, lozero:$disp),
(LEASLrri $base, $idx, (HI32 $disp))>;

// Multiclass for load instructions.
let mayLoad = 1, hasSideEffects = 0 in
multiclass LOADm<string opcStr, bits<8> opc, RegisterClass RC, ValueType Ty,
Expand Down Expand Up @@ -1566,6 +1556,50 @@ def : Pat<(i64 imm:$val),
(LEASLrii (ANDrm (LEAzii 0, 0, (LO32 imm:$val)), !add(32, 64)), 0,
(HI32 imm:$val))>;

// LEA patterns
def lea_add : PatFrags<(ops node:$base, node:$idx, node:$disp),
[(add (add node:$base, node:$idx), node:$disp),
(add (add node:$base, node:$disp), node:$idx),
(add node:$base, (add $idx, $disp))]>;
def : Pat<(lea_add I64:$base, simm7:$idx, simm32:$disp),
(LEArii $base, (LO7 $idx), (LO32 $disp))>;
def : Pat<(lea_add I64:$base, I64:$idx, simm32:$disp),
(LEArri $base, $idx, (LO32 $disp))>;
def : Pat<(lea_add I64:$base, simm7:$idx, lozero:$disp),
(LEASLrii $base, (LO7 $idx), (HI32 $disp))>;
def : Pat<(lea_add I64:$base, I64:$idx, lozero:$disp),
(LEASLrri $base, $idx, (HI32 $disp))>;

// Address calculation patterns and optimizations
//
// Generate following instructions:
// 1. LEA %reg, label@LO32
// AND %reg, %reg, (32)0
// 2. LEASL %reg, label@HI32
// 3. (LEA %reg, label@LO32)
// (AND %reg, %reg, (32)0)
// LEASL %reg, label@HI32(, %reg)
// 4. (LEA %reg, label@LO32)
// (AND %reg, %reg, (32)0)
// LEASL %reg, label@HI32(%reg, %got)
//
def velo_only : OutPatFrag<(ops node:$lo),
(ANDrm (LEAzii 0, 0, $lo), !add(32, 64))>;
def vehi_only : OutPatFrag<(ops node:$hi),
(LEASLzii 0, 0, $hi)>;
def vehi_lo : OutPatFrag<(ops node:$hi, node:$lo),
(LEASLrii $lo, 0, $hi)>;
def vehi_baselo : OutPatFrag<(ops node:$base, node:$hi, node:$lo),
(LEASLrri $base, $lo, $hi)>;
foreach type = [ "tblockaddress", "tconstpool", "texternalsym", "tglobaladdr",
"tglobaltlsaddr" ] in {
def : Pat<(VElo !cast<SDNode>(type):$lo), (velo_only $lo)>;
def : Pat<(VEhi !cast<SDNode>(type):$hi), (vehi_only $hi)>;
def : Pat<(add (VEhi !cast<SDNode>(type):$hi), I64:$lo), (vehi_lo $hi, $lo)>;
def : Pat<(add I64:$base, (add (VEhi !cast<SDNode>(type):$hi), I64:$lo)),
(vehi_baselo $base, $hi, $lo)>;
}

// floating point
def : Pat<(f32 fpimm:$val),
(EXTRACT_SUBREG (LEASLzii 0, 0, (HIFP32 $val)), sub_f32)>;
Expand Down Expand Up @@ -1813,46 +1847,6 @@ defm : TRATMSTm<atomic_store_8, i32, ST1Brri, ST1Brii, ST1Bzri, ST1Bzii>;
defm : TRATMSTm<atomic_store_16, i32, ST2Brri, ST2Brii, ST2Bzri, ST2Bzii>;
defm : TRATMSTm<atomic_store_32, i32, STLrri, STLrii, STLzri, STLzii>;

// Address calculation and its optimization
def : Pat<(VEhi tconstpool:$in), (LEASLzii 0, 0, tconstpool:$in)>;
def : Pat<(VElo tconstpool:$in),
(ANDrm (LEAzii 0, 0, tconstpool:$in), !add(32, 64))>;
def : Pat<(add (VEhi tconstpool:$in1), (VElo tconstpool:$in2)),
(LEASLrii (ANDrm (LEAzii 0, 0, tconstpool:$in2), !add(32, 64)), 0,
(tconstpool:$in1))>;

// Address calculation and its optimization
def : Pat<(VEhi tglobaladdr:$in), (LEASLzii 0, 0, tglobaladdr:$in)>;
def : Pat<(VElo tglobaladdr:$in),
(ANDrm (LEAzii 0, 0, tglobaladdr:$in), !add(32, 64))>;
def : Pat<(add (VEhi tglobaladdr:$in1), (VElo tglobaladdr:$in2)),
(LEASLrii (ANDrm (LEAzii 0, 0, tglobaladdr:$in2), !add(32, 64)), 0,
(tglobaladdr:$in1))>;

// Address calculation and its optimization
def : Pat<(VEhi tblockaddress:$in), (LEASLzii 0, 0, tblockaddress:$in)>;
def : Pat<(VElo tblockaddress:$in),
(ANDrm (LEAzii 0, 0, tblockaddress:$in), !add(32, 64))>;
def : Pat<(add (VEhi tblockaddress:$in1), (VElo tblockaddress:$in2)),
(LEASLrii (ANDrm (LEAzii 0, 0, tblockaddress:$in2), !add(32, 64)), 0,
(tblockaddress:$in1))>;

// GlobalTLS address calculation and its optimization
def : Pat<(VEhi tglobaltlsaddr:$in), (LEASLzii 0, 0, tglobaltlsaddr:$in)>;
def : Pat<(VElo tglobaltlsaddr:$in),
(ANDrm (LEAzii 0, 0, tglobaltlsaddr:$in), !add(32, 64))>;
def : Pat<(add (VEhi tglobaltlsaddr:$in1), (VElo tglobaltlsaddr:$in2)),
(LEASLrii (ANDrm (LEAzii 0, 0, tglobaltlsaddr:$in2), !add(32, 64)), 0,
(tglobaltlsaddr:$in1))>;

// Address calculation and its optimization
def : Pat<(VEhi texternalsym:$in), (LEASLzii 0, 0, texternalsym:$in)>;
def : Pat<(VElo texternalsym:$in),
(ANDrm (LEAzii 0, 0, texternalsym:$in), !add(32, 64))>;
def : Pat<(add (VEhi texternalsym:$in1), (VElo texternalsym:$in2)),
(LEASLrii (ANDrm (LEAzii 0, 0, texternalsym:$in2), !add(32, 64)), 0,
(texternalsym:$in1))>;

// Branches
def : Pat<(br bb:$addr), (BRCFLa bb:$addr)>;

Expand Down
Loading

0 comments on commit 3a0ab31

Please sign in to comment.