Skip to content

Commit 5061218

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ea2d2d10ee1e' from llvm.org/main into experimental/cas/main
2 parents 53dcbc5 + ea2d2d1 commit 5061218

File tree

10 files changed

+292
-18
lines changed

10 files changed

+292
-18
lines changed

llvm/lib/Target/AVR/AVRISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,12 @@ bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
11511151
return false;
11521152
}
11531153

1154+
// FIXME: We temporarily disable post increment load from program memory,
1155+
// due to bug https://github.com/llvm/llvm-project/issues/59914.
1156+
if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
1157+
if (AVR::isProgramMemoryAccess(LD))
1158+
return false;
1159+
11541160
Base = Op->getOperand(0);
11551161
Offset = DAG.getConstant(RHSC, DL, MVT::i8);
11561162
AM = ISD::POST_INC;

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,27 @@ bool LoongArchTargetLowering::decomposeMulByConstant(LLVMContext &Context,
31653165
((Imm - 2).isPowerOf2() || (Imm - 4).isPowerOf2() ||
31663166
(Imm - 8).isPowerOf2() || (Imm - 16).isPowerOf2()))
31673167
return true;
3168+
// Break (MUL x, imm) into (ADD (SLLI x, s0), (SLLI x, s1)),
3169+
// in which the immediate has two set bits. Or Break (MUL x, imm)
3170+
// into (SUB (SLLI x, s0), (SLLI x, s1)), in which the immediate
3171+
// equals to (1 << s0) - (1 << s1).
3172+
if (ConstNode->hasOneUse() && !(Imm.sge(-2048) && Imm.sle(4095))) {
3173+
unsigned Shifts = Imm.countr_zero();
3174+
// Reject immediates which can be composed via a single LUI.
3175+
if (Shifts >= 12)
3176+
return false;
3177+
// Reject multiplications can be optimized to
3178+
// (SLLI (ALSL x, x, 1/2/3/4), s).
3179+
APInt ImmPop = Imm.ashr(Shifts);
3180+
if (ImmPop == 3 || ImmPop == 5 || ImmPop == 9 || ImmPop == 17)
3181+
return false;
3182+
// We do not consider the case `(-Imm - ImmSmall).isPowerOf2()`,
3183+
// since it needs one more instruction than other 3 cases.
3184+
APInt ImmSmall = APInt(Imm.getBitWidth(), 1 << Shifts, true);
3185+
if ((Imm - ImmSmall).isPowerOf2() || (Imm + ImmSmall).isPowerOf2() ||
3186+
(ImmSmall - Imm).isPowerOf2())
3187+
return true;
3188+
}
31683189
}
31693190

31703191
return false;

llvm/test/CodeGen/AVR/load.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,18 @@ while.end: ; preds = %while.body, %entry
140140
%r.0.lcssa = phi i16 [ 0, %entry ], [ %add, %while.body ]
141141
ret i16 %r.0.lcssa
142142
}
143+
144+
define ptr addrspace(1) @load16_postinc_progmem(ptr addrspace(1) readonly %0) {
145+
; CHECK-LABEL: load16_postinc_progmem:
146+
; CHECK: movw r30, [[REG0:r[0-9]+]]
147+
; CHECK: lpm [[REG1:r[0-9]+]], Z+
148+
; CHECK: lpm [[REG1:r[0-9]+]], Z
149+
; CHECK: call foo
150+
; CHECK: adiw [[REG0:r[0-9]+]], 2
151+
%2 = load i16, ptr addrspace(1) %0, align 1
152+
tail call addrspace(1) void @foo(i16 %2)
153+
%3 = getelementptr inbounds i16, ptr addrspace(1) %0, i16 1
154+
ret ptr addrspace(1) %3
155+
}
156+
157+
declare void @foo(i16)

llvm/test/CodeGen/LoongArch/ir-instruction/mul.ll

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,3 +1304,218 @@ define i64 @mul_i64_4352(i64 %a) {
13041304
%b = mul i64 %a, 4352
13051305
ret i64 %b
13061306
}
1307+
1308+
define signext i32 @mul_i32_65792(i32 %a) {
1309+
; LA32-LABEL: mul_i32_65792:
1310+
; LA32: # %bb.0:
1311+
; LA32-NEXT: slli.w $a1, $a0, 8
1312+
; LA32-NEXT: slli.w $a0, $a0, 16
1313+
; LA32-NEXT: add.w $a0, $a0, $a1
1314+
; LA32-NEXT: ret
1315+
;
1316+
; LA64-LABEL: mul_i32_65792:
1317+
; LA64: # %bb.0:
1318+
; LA64-NEXT: slli.d $a1, $a0, 8
1319+
; LA64-NEXT: slli.d $a0, $a0, 16
1320+
; LA64-NEXT: add.w $a0, $a0, $a1
1321+
; LA64-NEXT: ret
1322+
%b = mul i32 %a, 65792
1323+
ret i32 %b
1324+
}
1325+
1326+
define signext i32 @mul_i32_65280(i32 %a) {
1327+
; LA32-LABEL: mul_i32_65280:
1328+
; LA32: # %bb.0:
1329+
; LA32-NEXT: slli.w $a1, $a0, 8
1330+
; LA32-NEXT: slli.w $a0, $a0, 16
1331+
; LA32-NEXT: sub.w $a0, $a0, $a1
1332+
; LA32-NEXT: ret
1333+
;
1334+
; LA64-LABEL: mul_i32_65280:
1335+
; LA64: # %bb.0:
1336+
; LA64-NEXT: slli.d $a1, $a0, 8
1337+
; LA64-NEXT: slli.d $a0, $a0, 16
1338+
; LA64-NEXT: sub.w $a0, $a0, $a1
1339+
; LA64-NEXT: ret
1340+
%b = mul i32 %a, 65280
1341+
ret i32 %b
1342+
}
1343+
1344+
define signext i32 @mul_i32_minus_65280(i32 %a) {
1345+
; LA32-LABEL: mul_i32_minus_65280:
1346+
; LA32: # %bb.0:
1347+
; LA32-NEXT: slli.w $a1, $a0, 16
1348+
; LA32-NEXT: slli.w $a0, $a0, 8
1349+
; LA32-NEXT: sub.w $a0, $a0, $a1
1350+
; LA32-NEXT: ret
1351+
;
1352+
; LA64-LABEL: mul_i32_minus_65280:
1353+
; LA64: # %bb.0:
1354+
; LA64-NEXT: slli.d $a1, $a0, 16
1355+
; LA64-NEXT: slli.d $a0, $a0, 8
1356+
; LA64-NEXT: sub.w $a0, $a0, $a1
1357+
; LA64-NEXT: ret
1358+
%b = mul i32 %a, -65280
1359+
ret i32 %b
1360+
}
1361+
1362+
define i64 @mul_i64_65792(i64 %a) {
1363+
; LA32-LABEL: mul_i64_65792:
1364+
; LA32: # %bb.0:
1365+
; LA32-NEXT: lu12i.w $a2, 16
1366+
; LA32-NEXT: ori $a2, $a2, 256
1367+
; LA32-NEXT: mul.w $a1, $a1, $a2
1368+
; LA32-NEXT: mulh.wu $a3, $a0, $a2
1369+
; LA32-NEXT: add.w $a1, $a3, $a1
1370+
; LA32-NEXT: mul.w $a0, $a0, $a2
1371+
; LA32-NEXT: ret
1372+
;
1373+
; LA64-LABEL: mul_i64_65792:
1374+
; LA64: # %bb.0:
1375+
; LA64-NEXT: slli.d $a1, $a0, 8
1376+
; LA64-NEXT: slli.d $a0, $a0, 16
1377+
; LA64-NEXT: add.d $a0, $a0, $a1
1378+
; LA64-NEXT: ret
1379+
%b = mul i64 %a, 65792
1380+
ret i64 %b
1381+
}
1382+
1383+
define i64 @mul_i64_65280(i64 %a) {
1384+
; LA32-LABEL: mul_i64_65280:
1385+
; LA32: # %bb.0:
1386+
; LA32-NEXT: lu12i.w $a2, 15
1387+
; LA32-NEXT: ori $a2, $a2, 3840
1388+
; LA32-NEXT: mul.w $a1, $a1, $a2
1389+
; LA32-NEXT: mulh.wu $a3, $a0, $a2
1390+
; LA32-NEXT: add.w $a1, $a3, $a1
1391+
; LA32-NEXT: mul.w $a0, $a0, $a2
1392+
; LA32-NEXT: ret
1393+
;
1394+
; LA64-LABEL: mul_i64_65280:
1395+
; LA64: # %bb.0:
1396+
; LA64-NEXT: slli.d $a1, $a0, 8
1397+
; LA64-NEXT: slli.d $a0, $a0, 16
1398+
; LA64-NEXT: sub.d $a0, $a0, $a1
1399+
; LA64-NEXT: ret
1400+
%b = mul i64 %a, 65280
1401+
ret i64 %b
1402+
}
1403+
1404+
define i64 @mul_i64_minus_65280(i64 %a) {
1405+
; LA32-LABEL: mul_i64_minus_65280:
1406+
; LA32: # %bb.0:
1407+
; LA32-NEXT: lu12i.w $a2, -16
1408+
; LA32-NEXT: ori $a2, $a2, 256
1409+
; LA32-NEXT: mul.w $a1, $a1, $a2
1410+
; LA32-NEXT: mulh.wu $a3, $a0, $a2
1411+
; LA32-NEXT: sub.w $a3, $a3, $a0
1412+
; LA32-NEXT: add.w $a1, $a3, $a1
1413+
; LA32-NEXT: mul.w $a0, $a0, $a2
1414+
; LA32-NEXT: ret
1415+
;
1416+
; LA64-LABEL: mul_i64_minus_65280:
1417+
; LA64: # %bb.0:
1418+
; LA64-NEXT: slli.d $a1, $a0, 16
1419+
; LA64-NEXT: slli.d $a0, $a0, 8
1420+
; LA64-NEXT: sub.d $a0, $a0, $a1
1421+
; LA64-NEXT: ret
1422+
%b = mul i64 %a, -65280
1423+
ret i64 %b
1424+
}
1425+
1426+
;; This multiplication is not transformed, due to
1427+
;; 1088 can be composed via a single ORI.
1428+
define i64 @mul_i64_1088(i64 %a) {
1429+
; LA32-LABEL: mul_i64_1088:
1430+
; LA32: # %bb.0:
1431+
; LA32-NEXT: ori $a2, $zero, 1088
1432+
; LA32-NEXT: mul.w $a1, $a1, $a2
1433+
; LA32-NEXT: mulh.wu $a3, $a0, $a2
1434+
; LA32-NEXT: add.w $a1, $a3, $a1
1435+
; LA32-NEXT: mul.w $a0, $a0, $a2
1436+
; LA32-NEXT: ret
1437+
;
1438+
; LA64-LABEL: mul_i64_1088:
1439+
; LA64: # %bb.0:
1440+
; LA64-NEXT: alsl.d $a0, $a0, $a0, 4
1441+
; LA64-NEXT: slli.d $a0, $a0, 6
1442+
; LA64-NEXT: ret
1443+
%b = mul i64 %a, 1088
1444+
ret i64 %b
1445+
}
1446+
1447+
;; This multiplication is not transformed, due to
1448+
;; -992 can be composed via a single ADDI.
1449+
define i64 @mul_i64_minus_992(i64 %a) {
1450+
; LA32-LABEL: mul_i64_minus_992:
1451+
; LA32: # %bb.0:
1452+
; LA32-NEXT: addi.w $a2, $zero, -992
1453+
; LA32-NEXT: mul.w $a1, $a1, $a2
1454+
; LA32-NEXT: mulh.wu $a3, $a0, $a2
1455+
; LA32-NEXT: sub.w $a3, $a3, $a0
1456+
; LA32-NEXT: add.w $a1, $a3, $a1
1457+
; LA32-NEXT: mul.w $a0, $a0, $a2
1458+
; LA32-NEXT: ret
1459+
;
1460+
; LA64-LABEL: mul_i64_minus_992:
1461+
; LA64: # %bb.0:
1462+
; LA64-NEXT: addi.w $a1, $zero, -992
1463+
; LA64-NEXT: mul.d $a0, $a0, $a1
1464+
; LA64-NEXT: ret
1465+
%b = mul i64 %a, -992
1466+
ret i64 %b
1467+
}
1468+
1469+
;; This multiplication is not transformed, due to
1470+
;; 4456448 can be composed via a single LUI.
1471+
define i64 @mul_i64_4456448(i64 %a) {
1472+
; LA32-LABEL: mul_i64_4456448:
1473+
; LA32: # %bb.0:
1474+
; LA32-NEXT: lu12i.w $a2, 1088
1475+
; LA32-NEXT: mul.w $a1, $a1, $a2
1476+
; LA32-NEXT: mulh.wu $a3, $a0, $a2
1477+
; LA32-NEXT: add.w $a1, $a3, $a1
1478+
; LA32-NEXT: mul.w $a0, $a0, $a2
1479+
; LA32-NEXT: ret
1480+
;
1481+
; LA64-LABEL: mul_i64_4456448:
1482+
; LA64: # %bb.0:
1483+
; LA64-NEXT: alsl.d $a0, $a0, $a0, 4
1484+
; LA64-NEXT: slli.d $a0, $a0, 18
1485+
; LA64-NEXT: ret
1486+
%b = mul i64 %a, 4456448
1487+
ret i64 %b
1488+
}
1489+
1490+
;; This multiplication is not transformed, due to
1491+
;; 65280 is used multiple times.
1492+
define i64 @mul_i64_65280_twice(i64 %a, i64 %b) {
1493+
; LA32-LABEL: mul_i64_65280_twice:
1494+
; LA32: # %bb.0:
1495+
; LA32-NEXT: lu12i.w $a4, 15
1496+
; LA32-NEXT: ori $a4, $a4, 3840
1497+
; LA32-NEXT: mul.w $a3, $a3, $a4
1498+
; LA32-NEXT: mulh.wu $a5, $a2, $a4
1499+
; LA32-NEXT: add.w $a3, $a5, $a3
1500+
; LA32-NEXT: mul.w $a1, $a1, $a4
1501+
; LA32-NEXT: mulh.wu $a5, $a0, $a4
1502+
; LA32-NEXT: add.w $a1, $a5, $a1
1503+
; LA32-NEXT: xor $a1, $a1, $a3
1504+
; LA32-NEXT: mul.w $a2, $a2, $a4
1505+
; LA32-NEXT: mul.w $a0, $a0, $a4
1506+
; LA32-NEXT: xor $a0, $a0, $a2
1507+
; LA32-NEXT: ret
1508+
;
1509+
; LA64-LABEL: mul_i64_65280_twice:
1510+
; LA64: # %bb.0:
1511+
; LA64-NEXT: lu12i.w $a2, 15
1512+
; LA64-NEXT: ori $a2, $a2, 3840
1513+
; LA64-NEXT: mul.d $a1, $a1, $a2
1514+
; LA64-NEXT: mul.d $a0, $a0, $a2
1515+
; LA64-NEXT: xor $a0, $a0, $a1
1516+
; LA64-NEXT: ret
1517+
%c = mul i64 %a, 65280
1518+
%d = mul i64 %b, 65280
1519+
%e = xor i64 %c, %d
1520+
ret i64 %e
1521+
}

mlir/include/mlir/Dialect/Transform/IR/TransformOps.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class TrackingListener : public RewriterBase::Listener,
5050
virtual Operation *findReplacementOp(Operation *op,
5151
ValueRange newValues) const;
5252

53+
/// Notify the listener that the pattern failed to match the given operation,
54+
/// and provide a callback to populate a diagnostic with the reason why the
55+
/// failure occurred.
56+
LogicalResult
57+
notifyMatchFailure(Location loc,
58+
function_ref<void(Diagnostic &)> reasonCallback) override;
59+
5360
/// This function is called when a tracked payload op is dropped because no
5461
/// replacement op was found. Derived classes can implement this function for
5562
/// custom error handling.

mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,16 @@ Value mlir::sparse_tensor::genIsNonzero(OpBuilder &builder, mlir::Location loc,
244244
}
245245

246246
void mlir::sparse_tensor::genReshapeDstShape(
247-
Location loc, PatternRewriter &rewriter, SmallVectorImpl<Value> &dstShape,
247+
OpBuilder &builder, Location loc, SmallVectorImpl<Value> &dstShape,
248248
ArrayRef<Value> srcShape, ArrayRef<StaticSize> staticDstShape,
249249
ArrayRef<ReassociationIndices> reassociation) {
250250
// Collapse shape.
251251
if (reassociation.size() < srcShape.size()) {
252252
unsigned start = 0;
253253
for (const auto &map : llvm::enumerate(reassociation)) {
254-
auto dstDim = constantIndex(rewriter, loc, 1);
254+
auto dstDim = constantIndex(builder, loc, 1);
255255
for (unsigned i = start; i < start + map.value().size(); i++) {
256-
dstDim = rewriter.create<arith::MulIOp>(loc, dstDim, srcShape[i]);
256+
dstDim = builder.create<arith::MulIOp>(loc, dstDim, srcShape[i]);
257257
}
258258
dstShape.push_back(dstDim);
259259
start = start + map.value().size();
@@ -285,13 +285,13 @@ void mlir::sparse_tensor::genReshapeDstShape(
285285
}
286286
}
287287
// Compute the dynamic dimension size.
288-
Value productVal = constantIndex(rewriter, loc, product);
288+
Value productVal = constantIndex(builder, loc, product);
289289
Value dynamicSize =
290-
rewriter.create<arith::DivUIOp>(loc, srcDim, productVal);
290+
builder.create<arith::DivUIOp>(loc, srcDim, productVal);
291291
dstShape.push_back(dynamicSize);
292292
} else {
293293
// The expanded dimension is statically known.
294-
dstShape.push_back(constantIndex(rewriter, loc, staticDstShape[j]));
294+
dstShape.push_back(constantIndex(builder, loc, staticDstShape[j]));
295295
}
296296
}
297297
start = start + map.size();
@@ -512,8 +512,8 @@ Operation *mlir::sparse_tensor::getTop(Operation *op) {
512512
}
513513

514514
void sparse_tensor::foreachInSparseConstant(
515-
Location loc, RewriterBase &rewriter, SparseElementsAttr attr,
516-
AffineMap order, function_ref<void(ArrayRef<Value>, Value)> callback) {
515+
OpBuilder &builder, Location loc, SparseElementsAttr attr, AffineMap order,
516+
function_ref<void(ArrayRef<Value>, Value)> callback) {
517517
const Dimension dimRank = getSparseTensorType(attr).getDimRank();
518518
const auto coordinates = attr.getIndices().getValues<IntegerAttr>();
519519
const auto values = attr.getValues().getValues<Attribute>();
@@ -560,17 +560,17 @@ void sparse_tensor::foreachInSparseConstant(
560560
cvs.clear();
561561
for (Dimension d = 0; d < dimRank; d++) {
562562
auto crd = elems[i].first[d].getInt();
563-
cvs.push_back(rewriter.create<arith::ConstantIndexOp>(loc, crd));
563+
cvs.push_back(builder.create<arith::ConstantIndexOp>(loc, crd));
564564
}
565565
// Remap value.
566566
Value val;
567567
if (attr.getElementType().isa<ComplexType>()) {
568568
auto valAttr = elems[i].second.cast<ArrayAttr>();
569-
val = rewriter.create<complex::ConstantOp>(loc, attr.getElementType(),
570-
valAttr);
569+
val = builder.create<complex::ConstantOp>(loc, attr.getElementType(),
570+
valAttr);
571571
} else {
572572
auto valAttr = elems[i].second.cast<TypedAttr>();
573-
val = rewriter.create<arith::ConstantOp>(loc, valAttr);
573+
val = builder.create<arith::ConstantOp>(loc, valAttr);
574574
}
575575
assert(val);
576576
callback(cvs, val);

mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Value genIsNonzero(OpBuilder &builder, Location loc, Value v);
8989
/// Computes the shape of destination tensor of a reshape operator. This is only
9090
/// used when operands have dynamic shape. The shape of the destination is
9191
/// stored into dstShape.
92-
void genReshapeDstShape(Location loc, PatternRewriter &rewriter,
92+
void genReshapeDstShape(OpBuilder &builder, Location loc,
9393
SmallVectorImpl<Value> &dstShape,
9494
ArrayRef<Value> srcShape,
9595
ArrayRef<StaticSize> staticDstShape,
@@ -211,8 +211,8 @@ Operation *getTop(Operation *op);
211211
/// %v3 = complex.constant (5.0, 6.0)
212212
/// callback({%c3}, %v3)
213213
void foreachInSparseConstant(
214-
Location loc, RewriterBase &rewriter, SparseElementsAttr attr,
215-
AffineMap order, function_ref<void(ArrayRef<Value>, Value)> callback);
214+
OpBuilder &builder, Location loc, SparseElementsAttr attr, AffineMap order,
215+
function_ref<void(ArrayRef<Value>, Value)> callback);
216216

217217
/// Loads `size`-many values from the memref, which must have rank-1 and
218218
/// size greater-or-equal to `size`. If the optional `(offsetIdx,offsetVal)`

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ genSparse2SparseReshape(ReshapeOp op, typename ReshapeOp::Adaptor adaptor,
489489
// Static "shapes" are in fact "sizes".
490490
fillDimShape(rewriter, loc, dstTp, dstDimSizes);
491491
else
492-
genReshapeDstShape(loc, rewriter, dstDimSizes, srcDimSizes,
492+
genReshapeDstShape(rewriter, loc, dstDimSizes, srcDimSizes,
493493
dstTp.getDimShape(), op.getReassociationIndices());
494494
const Value coo =
495495
params.genBuffers(dstTp, dstDimSizes).genNewCall(Action::kEmptyCOO);

0 commit comments

Comments
 (0)