Skip to content

Commit 970d69c

Browse files
committed
[CIR] Implement more of CheckAggExprForMemSetUse()
Implement another early return so the empty lambda also bail for this optimization -- in particular not performing it for small types. Fixes #6.
1 parent f5b1b06 commit 970d69c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E,
299299
return;
300300
}
301301

302+
// If the type is 16-bytes or smaller, prefer individual stores over memset.
303+
CharUnits Size = Slot.getPreferredSize(CGF.getContext(), E->getType());
304+
if (Size <= CharUnits::fromQuantity(16))
305+
return;
306+
302307
llvm_unreachable("NYI");
303308
}
304309

clang/lib/CIR/CodeGen/CIRGenValue.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ class AggValueSlot {
364364
bool isSanitizerChecked() const { return SanitizerCheckedFlag; }
365365

366366
IsZeroed_t isZeroed() const { return IsZeroed_t(ZeroedFlag); }
367+
368+
/// Get the preferred size to use when storing a value to this slot. This
369+
/// is the type size unless that might overlap another object, in which
370+
/// case it's the dsize.
371+
clang::CharUnits getPreferredSize(clang::ASTContext &Ctx, clang::QualType Type) {
372+
return mayOverlap() ? Ctx.getTypeInfoDataSizeInChars(Type).Width
373+
: Ctx.getTypeSizeInChars(Type);
374+
}
367375
};
368376

369377
} // namespace cir

clang/test/CIR/CodeGen/lambda.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir-enable -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s
3-
// XFAIL: *
43

54
void fn() {
65
auto a = [](){};

0 commit comments

Comments
 (0)