[llvm] [X86] For minsize, use size for alignment, rather than actual alignment (PR #87003)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 5 11:24:35 PDT 2024


================
@@ -67,10 +67,27 @@ SDValue X86SelectionDAGInfo::EmitTargetCodeForMemset(
   // The libc version is likely to be faster for these cases. It can use the
   // address value and run time information about the CPU.
   if (Alignment < Align(4) || !ConstantSize ||
-      ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold()) 
+      ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold())
     return SDValue();
 
+  // If we have minsize, then don't care about the alignment.
+  // On x86, the CPU doesn't care and neither should you.
+  // As long as the count is aligned, we can use the minimum number of
+  // instructions without always having to resort to strosb.
+  //
+  // Because this is a feature specific to x86, we must handle it here.
   uint64_t SizeVal = ConstantSize->getZExtValue();
+  if (DAG.getMachineFunction().getFunction().hasMinSize()) {
+    if ((SizeVal & 7) == 0 && Subtarget.is64Bit())
----------------
topperc wrote:

I think you can do something like `commonAlignment(Align(Subtarget.is64Bit() ? 8 : 4), SizeVal)` instead of this if/else chain.

https://github.com/llvm/llvm-project/pull/87003


More information about the llvm-commits mailing list