Skip to content

Commit 15de98a

Browse files
committed
address code review comments
1 parent 999e35d commit 15de98a

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -766,20 +766,20 @@ class ScalarExprEmitter
766766
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Ops.FPFeatures);
767767
if (LHSMatTy && RHSMatTy) {
768768
// Note that SME only has non-widening MOPA for float32 and float64, so
769-
// only these two types have native SME matmul operations. For other
770-
// types, SVE version is used. We hope that SVE version is better than
771-
// default NEON or scalar version.
772-
auto Ty = LHSMatTy->getElementType();
773-
if (!CGF.getContext().getTargetInfo().hasFeature("sme") ||
774-
!MatrixType::isValidTypeForSME(Ty))
769+
// only these two types have native SME matmul operations. For other
770+
// types, SVE version is used. We hope that SVE version is better than
771+
// default NEON or scalar version.
772+
auto Ty = LHSMatTy->getElementType();
773+
if (!CGF.getContext().getTargetInfo().hasFeature("sme") ||
774+
!MatrixType::isValidTypeForSME(Ty))
775775
return MB.CreateMatrixMultiply(
776-
Ops.LHS, Ops.RHS, LHSMatTy->getNumRows(),
777-
LHSMatTy->getNumColumns(), RHSMatTy->getNumColumns());
776+
Ops.LHS, Ops.RHS, LHSMatTy->getNumRows(),
777+
LHSMatTy->getNumColumns(), RHSMatTy->getNumColumns());
778778
assert(isa<BuiltinType>(Ty) && "SME types should be BuiltinType.");
779779
return MB.CreateSMEMatrixMultiply(
780-
Ops.LHS, Ops.RHS, LHSMatTy->getNumRows(), LHSMatTy->getNumColumns(),
780+
Ops.LHS, Ops.RHS, LHSMatTy->getNumRows(), LHSMatTy->getNumColumns(),
781781
RHSMatTy->getNumColumns(),
782-
cast<BuiltinType>(Ty)->isSignedInteger());
782+
cast<BuiltinType>(Ty)->isSignedInteger());
783783
}
784784
return MB.CreateScalarMultiply(Ops.LHS, Ops.RHS);
785785
}
@@ -4192,7 +4192,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) {
41924192
assert(isa<BuiltinType>(Ty) && "SME types should be BuiltinType.");
41934193
return MB.CreateSMEMatrixBinOp(
41944194
op.LHS, op.RHS, MatTy->getNumRows(), MatTy->getNumColumns(),
4195-
cast<BuiltinType>(Ty)->isSignedInteger(), "add");
4195+
cast<BuiltinType>(Ty)->isSignedInteger(), "add");
41964196
}
41974197

41984198
if (op.Ty->isUnsignedIntegerType() &&
@@ -4349,14 +4349,14 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) {
43494349
llvm::MatrixBuilder MB(Builder);
43504350
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, op.FPFeatures);
43514351
auto *MatTy =
4352-
cast<ConstantMatrixType>(op.E->getType().getCanonicalType());
4352+
cast<ConstantMatrixType>(op.E->getType().getCanonicalType());
43534353
auto Ty = MatTy->getElementType();
43544354
if (!CGF.getContext().getTargetInfo().hasFeature("sme") ||
43554355
!MatrixType::isValidTypeForSME(Ty))
4356-
return MB.CreateSub(op.LHS, op.RHS);
4356+
return MB.CreateSub(op.LHS, op.RHS);
43574357
assert(isa<BuiltinType>(Ty) && "SME types should be BuiltinType.");
43584358
return MB.CreateSMEMatrixBinOp(
4359-
op.LHS, op.RHS, MatTy->getNumRows(), MatTy->getNumColumns(),
4359+
op.LHS, op.RHS, MatTy->getNumRows(), MatTy->getNumColumns(),
43604360
cast<BuiltinType>(Ty)->isSignedInteger(), "sub");
43614361
}
43624362

llvm/include/llvm/IR/MatrixBuilder.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ class MatrixBuilder {
6161
if (!isa<LoadInst>(StoredValue))
6262
return Addr;
6363

64-
return cast<LoadInst>(StoredValue)->getPointerOperand();
64+
Value *Ptr = cast<LoadInst>(StoredValue)->getPointerOperand();
65+
// If Ptr is used once, its memory may be altered.
66+
if (!Ptr->hasNUses(1))
67+
return Addr;
68+
return Ptr;
6569
}
6670

6771
std::pair<Value *, Value *> splatScalarOperandIfNeeded(Value *LHS,

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ static cl::opt<unsigned>
196196
extern cl::opt<bool> EnableMatrix;
197197

198198
static cl::opt<unsigned>
199-
BigBasicBlock("schedule-big-basic-block", cl::Hidden, cl::init(200),
200-
cl::desc("The limit to use while schedule a region "));
199+
BigBBThreshold("big-basic-block-threshold", cl::Hidden, cl::init(200),
200+
cl::desc("The limit to use while schedule a region when "
201+
"matrix opertion is enabled"));
201202

202203
// DAG subtrees must have at least this many nodes.
203204
static const unsigned MinSubtreeSize = 8;
@@ -642,7 +643,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
642643
MachineBasicBlock::iterator RegionEnd = R.RegionEnd;
643644
unsigned NumRegionInstrs = R.NumRegionInstrs;
644645

645-
if (EnableMatrix && NumRegionInstrs > BigBasicBlock)
646+
if (EnableMatrix && NumRegionInstrs > BigBBThreshold)
646647
continue;
647648

648649
// Notify the scheduler of the region, even if we may skip scheduling

llvm/lib/CodeGen/ScheduleDAGInstrs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static cl::opt<bool> SchedPrintCycles(
9797
static unsigned getReductionSize() {
9898
// Always reduce a huge region with half of the elements, except
9999
// when user sets this number explicitly.
100+
// When matrix operation is enabled, reduce more aggressively to reduce
101+
// compile time impact.
100102
if (ReductionSize.getNumOccurrences() == 0) {
101103
if (EnableMatrix)
102104
return HugeRegion / 20;

0 commit comments

Comments
 (0)