llvm-project/clang/lib/CodeGen
Pengfei Wang d61cb749f4 [X86] Fix i386 struct and union parameter alignment
According to i386 System V ABI 2.1: Structures and unions assume the
alignment of their most strictly aligned component. But current
implementation always takes them as 4-byte aligned which will result
in incorrect code, e.g:

 1 #include <immintrin.h>
 2 typedef union {
 3         int d[4];
 4         __m128 m;
 5 } M128;
 6 extern void foo(int, ...);
 7 void test(void)
 8 {
 9   M128 a;
10   foo(1, a);
11   foo(1, a.m);
12 }

The first call (line 10) takes the second arg as 4-byte aligned while
the second call (line 11) takes the second arg as 16-byte aligned.
There is oxymoron for the alignment of the 2 calls because they should
be the same.

This patch fixes the bug by following i386 System V ABI and apply it to
Linux only since other System V OS (e.g Darwin, PS4 and FreeBSD) don't
want to spend any effort dealing with the ramifications of ABI breaks
at present.

Patch by Wei Xiao (wxiao3)

Differential Revision: https://reviews.llvm.org/D60748

llvm-svn: 361934
2019-05-29 08:42:35 +00:00
..
ABIInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Address.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BackendUtil.cpp [NewPassManager] Add tuning option: LoopUnrolling [clang-change] 2019-05-24 17:40:52 +00:00
CGAtomic.cpp add periods 2019-04-03 22:19:07 +00:00
CGBlocks.cpp Use llvm::stable_sort 2019-04-24 14:43:05 +00:00
CGBlocks.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGBuilder.h [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGBuiltin.cpp [clang] Handle lrint/llrint builtins 2019-05-28 21:16:04 +00:00
CGCUDANV.cpp [HIP-Clang] Fat binary should not be produced for non GPU code 2019-04-02 21:54:41 +00:00
CGCUDARuntime.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCUDARuntime.h [CUDA][HIP] Use device side kernel and variable names when registering them 2019-02-14 02:00:09 +00:00
CGCXX.cpp Fix unused variable warning. NFCI. 2019-03-23 16:16:46 +00:00
CGCXXABI.cpp Remove two unnecessary wrappers of canPassInRegisters 2019-04-30 22:23:20 +00:00
CGCXXABI.h Remove two unnecessary wrappers of canPassInRegisters 2019-04-30 22:23:20 +00:00
CGCall.cpp [COFF, ARM64] Fix ABI implementation of struct returns 2019-05-03 21:12:24 +00:00
CGCall.h [opaque pointer types] Make EmitCall pass Function Types to 2019-02-07 01:15:41 +00:00
CGClass.cpp Fix an off-by-one mistake in IRGen's copy-construction 2019-04-10 18:07:18 +00:00
CGCleanup.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGCleanup.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCoroutine.cpp [opaque pointer types] Trivial changes towards CallInst requiring 2019-02-03 21:53:49 +00:00
CGDebugInfo.cpp Fixed a -Wunused-variable warning when assertions are disabled 2019-05-22 17:45:24 +00:00
CGDebugInfo.h [codeview] Fix symbol names for dynamic initializers and atexit stubs 2019-04-24 22:45:44 +00:00
CGDecl.cpp Variable auto-init: don't initialize aggregate padding of all aggregates 2019-04-30 22:56:53 +00:00
CGDeclCXX.cpp [OpenCL] Make global ctor init function a kernel 2019-05-09 13:55:44 +00:00
CGException.cpp [WebAssembly] Use rethrow intrinsic in the rethrow block 2019-03-16 05:39:12 +00:00
CGExpr.cpp Implement __builtin_LINE() et. al. to support source location capture. 2019-05-16 21:04:15 +00:00
CGExprAgg.cpp Implement __builtin_LINE() et. al. to support source location capture. 2019-05-16 21:04:15 +00:00
CGExprCXX.cpp [c++20] Implement P1009R2: allow omitting the array bound in an array 2019-05-06 03:47:15 +00:00
CGExprComplex.cpp Implement __builtin_LINE() et. al. to support source location capture. 2019-05-16 21:04:15 +00:00
CGExprConstant.cpp Modules: Code generation of enum constants for merged enum definitions 2019-05-22 20:36:06 +00:00
CGExprScalar.cpp ScalarExprEmitter::EmitCompoundAssign - fix uninitialized variable warning. NFCI. 2019-05-18 12:17:15 +00:00
CGGPUBuiltin.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGLoopInfo.cpp [CodeGen] Generate follow-up metadata for loops with more than one transformation. 2019-04-01 17:47:41 +00:00
CGLoopInfo.h [CodeGen] Generate follow-up metadata for loops with more than one transformation. 2019-04-01 17:47:41 +00:00
CGNonTrivialStruct.cpp Add { } to silence compiler warning [NFC] 2019-04-11 06:57:12 +00:00
CGObjC.cpp [CodeGenObjC] invoke objc_autorelease, objc_retain when necessary 2019-05-15 20:15:01 +00:00
CGObjCGNU.cpp [gnustep-objc] Make the GNUstep v2 ABI work for Windows DLLs. 2019-03-31 11:22:33 +00:00
CGObjCMac.cpp [CodeGen][ObjC] Remove the leading `l_` from ObjC symbols and make 2019-05-09 17:43:52 +00:00
CGObjCRuntime.cpp [opaque pointer types] Pass function types for runtime function calls. 2019-02-05 16:42:33 +00:00
CGObjCRuntime.h [opaque pointer types] Pass function types for runtime function calls. 2019-02-05 16:42:33 +00:00
CGOpenCLRuntime.cpp [OpenCL] Simplify LLVM IR generated for OpenCL blocks 2019-02-21 11:02:10 +00:00
CGOpenCLRuntime.h [OpenCL] Simplify LLVM IR generated for OpenCL blocks 2019-02-21 11:02:10 +00:00
CGOpenMPRuntime.cpp [CGOpenMPRuntime] emitX86DeclareSimdFunction - assert simdlen/cdtsize is not zero. NFCI. 2019-05-22 13:02:19 +00:00
CGOpenMPRuntime.h [OpenMP] Add support for registering requires directives with the runtime 2019-05-21 19:42:01 +00:00
CGOpenMPRuntimeNVPTX.cpp [OpenMP] Add support for registering requires directives with the runtime 2019-05-21 19:42:01 +00:00
CGOpenMPRuntimeNVPTX.h [OpenMP] Add support for registering requires directives with the runtime 2019-05-21 19:42:01 +00:00
CGRecordLayout.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGRecordLayoutBuilder.cpp Use llvm::stable_sort 2019-04-24 14:43:05 +00:00
CGStmt.cpp [CodeGen] Consider tied operands when adjusting inline asm operands. 2019-03-14 19:46:51 +00:00
CGStmtOpenMP.cpp [OPENMP]Do not crash for const firstprivates. 2019-05-23 22:30:43 +00:00
CGVTT.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGVTables.cpp [CodeGen] Set construction vtable visibility after creating initializer 2019-02-11 20:13:42 +00:00
CGVTables.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGValue.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CMakeLists.txt Variable auto-init: also auto-init alloca 2019-04-12 00:11:27 +00:00
CodeGenABITypes.cpp Remove redundant FunctionDecl argument from a couple functions. 2019-02-02 01:48:23 +00:00
CodeGenAction.cpp Make SourceManager::createFileID(UnownedTag, ...) take a const llvm::MemoryBuffer* 2019-04-04 21:06:41 +00:00
CodeGenFunction.cpp Refactor: split Uninitialized state on APValue into an "Absent" state 2019-05-21 23:15:18 +00:00
CodeGenFunction.h Implement __builtin_LINE() et. al. to support source location capture. 2019-05-16 21:04:15 +00:00
CodeGenModule.cpp [CUDA][HIP] Emit dependent libs for host only 2019-05-28 21:18:59 +00:00
CodeGenModule.h [CodeGenModule] BlockByrefHelpers - add missing uninitialized variables to constructor. NFCI. 2019-05-21 11:37:54 +00:00
CodeGenPGO.cpp [MS] Don't emit coverage for deleting dtors 2019-02-26 20:42:52 +00:00
CodeGenPGO.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTBAA.cpp Fix file headers. NFC 2019-03-01 06:49:51 +00:00
CodeGenTBAA.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTypeCache.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTypes.cpp [OpenCL] Change type of block pointer for OpenCL 2019-02-19 15:19:06 +00:00
CodeGenTypes.h IRGen: Remove StructorType; thread GlobalDecl through more code. NFCI. 2019-03-22 23:05:10 +00:00
ConstantEmitter.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ConstantInitBuilder.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CoverageMappingGen.cpp Use llvm::stable_sort 2019-04-24 14:43:05 +00:00
CoverageMappingGen.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
EHScopeStack.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ItaniumCXXABI.cpp Assume `__cxa_allocate_exception` returns an under-aligned memory on 2019-05-10 02:16:37 +00:00
MacroPPCallbacks.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MacroPPCallbacks.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MicrosoftCXXABI.cpp [COFF, ARM64] Fix ABI implementation of struct returns 2019-05-03 21:12:24 +00:00
ModuleBuilder.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ObjectFilePCHContainerOperations.cpp Recommit [Object] Change object::SectionRef::getContents() to return Expected<StringRef> 2019-05-16 13:24:04 +00:00
PatternInit.cpp Variable auto-init: also auto-init alloca 2019-04-12 00:11:27 +00:00
PatternInit.h Variable auto-init: also auto-init alloca 2019-04-12 00:11:27 +00:00
README.txt
SanitizerMetadata.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SanitizerMetadata.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SwiftCallingConv.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
TargetInfo.cpp [X86] Fix i386 struct and union parameter alignment 2019-05-29 08:42:35 +00:00
TargetInfo.h AMDGPU: Add support for cross address space synchronization scopes (clang) 2019-03-25 20:54:00 +00:00
VarBypassDetector.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
VarBypassDetector.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00

README.txt

IRgen optimization opportunities.

//===---------------------------------------------------------------------===//

The common pattern of
--
short x; // or char, etc
(x == 10)
--
generates an zext/sext of x which can easily be avoided.

//===---------------------------------------------------------------------===//

Bitfields accesses can be shifted to simplify masking and sign
extension. For example, if the bitfield width is 8 and it is
appropriately aligned then is is a lot shorter to just load the char
directly.

//===---------------------------------------------------------------------===//

It may be worth avoiding creation of alloca's for formal arguments
for the common situation where the argument is never written to or has
its address taken. The idea would be to begin generating code by using
the argument directly and if its address is taken or it is stored to
then generate the alloca and patch up the existing code.

In theory, the same optimization could be a win for block local
variables as long as the declaration dominates all statements in the
block.

NOTE: The main case we care about this for is for -O0 -g compile time
performance, and in that scenario we will need to emit the alloca
anyway currently to emit proper debug info. So this is blocked by
being able to emit debug information which refers to an LLVM
temporary, not an alloca.

//===---------------------------------------------------------------------===//

We should try and avoid generating basic blocks which only contain
jumps. At -O0, this penalizes us all the way from IRgen (malloc &
instruction overhead), all the way down through code generation and
assembly time.

On 176.gcc:expr.ll, it looks like over 12% of basic blocks are just
direct branches!

//===---------------------------------------------------------------------===//