[PATCH] D60719: Demonstrate how to fix freestanding for memcpy

Clement Courbet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 17 01:37:43 PDT 2019

courbet added a comment.

As discussed offline, I think this should go through an RFC process.

I guess the main reservation that people will have is that this might generate a very large number of load stores (because we don't have a good way to generate loops here). This is not an issue for X86 because of REPMOVS, but it would be cool to have the opinion of people familiar with other architectures. One way to tackle this issue could be to expand existing `mem*` functions before the DAG. This is already happening for `memcmp` in `ExpandMemcmp`, which could be made aware of this flag. Similar approaches could be used for other `mem*` functions. But eventually this has to be handled here as the dag itself can call `getMemcpy()`.

Also, the current approach does not protect against current users and future unsavvy users calling `SelectionDAG::getMemcpy` with `AlwaysAlign == false`, so what about actually retrieving the flag //within// the function instead of outside ? This happens e.g. in `SelectionDAG::visitMemPCpyCall()`m `AArch64TargetLowering::LowerCall` and others.

Comment at: clang/test/CodeGen/freestanding-disables-libc.c:6
+// NOTE: Test that assembly doesn't call memcpy function in freestanding mode.
+// RUN: %clang_cc1 -triple i386-unknown-unknown -O2 -S %s -o - | grep 'memcpy'
That's the responsibility of LLVM, so this test should be in `llvm/test/Codegen`.

Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6093
+  assert(MF->getFunction().getParent()->getModuleFlag("force-inline-libc") ==
+         nullptr);
Please add an error message (maybe "modules with 'force-inline-libc' should never emit library calls")

Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5483
+static bool IsForceInlineLibc(const SelectionDAG &DAG) {
+  const Module *M = DAG.getMachineFunction().getFunction().getParent();

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list