Skip to content

Commit

Permalink
[CIR] Implement more of CheckAggExprForMemSetUse()
Browse files Browse the repository at this point in the history
Implement another early return so the empty lambda also
bail for this optimization -- in particular not performing
it for small types.

Fixes #6.
  • Loading branch information
cmarcelo authored and bcardosolopes committed Oct 18, 2022
1 parent f5b1b06 commit a5b975e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E,
return;
}

// If the type is 16-bytes or smaller, prefer individual stores over memset.
CharUnits Size = Slot.getPreferredSize(CGF.getContext(), E->getType());
if (Size <= CharUnits::fromQuantity(16))
return;

llvm_unreachable("NYI");
}

Expand Down
8 changes: 8 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ class AggValueSlot {
bool isSanitizerChecked() const { return SanitizerCheckedFlag; }

IsZeroed_t isZeroed() const { return IsZeroed_t(ZeroedFlag); }

/// Get the preferred size to use when storing a value to this slot. This
/// is the type size unless that might overlap another object, in which
/// case it's the dsize.
clang::CharUnits getPreferredSize(clang::ASTContext &Ctx, clang::QualType Type) {
return mayOverlap() ? Ctx.getTypeInfoDataSizeInChars(Type).Width
: Ctx.getTypeSizeInChars(Type);
}
};

} // namespace cir
Expand Down
1 change: 0 additions & 1 deletion clang/test/CIR/CodeGen/lambda.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir-enable -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s
// XFAIL: *

void fn() {
auto a = [](){};
Expand Down

0 comments on commit a5b975e

Please sign in to comment.