llvm-project/clang/lib/CodeGen
Chris Lattner 055097f024 If coercing something from int or pointer type to int or pointer type
(potentially after unwrapping it from a struct) do it without going through
memory.  We now compile:

struct DeclGroup {
  unsigned NumDecls;
};

int foo(DeclGroup D) {
  return D.NumDecls;
}

into:

%struct.DeclGroup = type { i32 }

define i32 @_Z3foo9DeclGroup(i64) nounwind ssp noredzone {
entry:
  %D = alloca %struct.DeclGroup, align 4          ; <%struct.DeclGroup*> [#uses=2]
  %coerce.dive = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %coerce.val.ii = trunc i64 %0 to i32            ; <i32> [#uses=1]
  store i32 %coerce.val.ii, i32* %coerce.dive
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %tmp1 = load i32* %tmp                          ; <i32> [#uses=1]
  ret i32 %tmp1
}

instead of:

%struct.DeclGroup = type { i32 }

define i32 @_Z3foo9DeclGroup(i64) nounwind ssp noredzone {
entry:
  %D = alloca %struct.DeclGroup, align 4          ; <%struct.DeclGroup*> [#uses=2]
  %tmp = alloca i64                               ; <i64*> [#uses=2]
  %coerce.dive = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  store i64 %0, i64* %tmp
  %1 = bitcast i64* %tmp to i32*                  ; <i32*> [#uses=1]
  %2 = load i32* %1, align 1                      ; <i32> [#uses=1]
  store i32 %2, i32* %coerce.dive
  %tmp1 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i32*> [#uses=1]
  %tmp2 = load i32* %tmp1                         ; <i32> [#uses=1]
  ret i32 %tmp2
}

... which is quite a bit less terrifying.

llvm-svn: 106975
2010-06-27 06:26:04 +00:00
..
ABIInfo.h x86-64 ABI: If a type is a C++ record with either a non-trivial destructor or a non-trivial copy constructor, it should be passed in a pointer. Daniel, plz review. 2009-09-16 15:53:40 +00:00
BackendUtil.cpp Move CodeGenOptions.h *back* into Frontend. This should have been done when the 2010-06-15 23:19:56 +00:00
CGBlocks.cpp Patch to correctly mangle block helper functions 2010-06-24 00:08:06 +00:00
CGBlocks.h Fixed a block regression caused by trying to use 2010-06-07 19:39:39 +00:00
CGBuilder.h Disable generation of basic block names in NDEBUG mode. 2008-11-12 00:01:12 +00:00
CGBuiltin.cpp Implement remaining codegen for NEON, all operations should now work. 2010-06-20 23:05:28 +00:00
CGCXX.cpp Switch over to the new caching version of getMangledName. 2010-06-22 16:16:50 +00:00
CGCXX.h Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
CGCXXABI.h Add a stub Microsoft Visual C++ ABI class (with stub mangler). 2010-06-09 23:25:41 +00:00
CGCall.cpp If coercing something from int or pointer type to int or pointer type 2010-06-27 06:26:04 +00:00
CGCall.h Remember the regparm attribute in FunctionType::ExtInfo. 2010-03-30 22:15:11 +00:00
CGClass.cpp Change EmitReferenceBindingToExpr to take a decl instead of a boolean. 2010-06-26 16:35:32 +00:00
CGDebugInfo.cpp Switch over to the new caching version of getMangledName. 2010-06-22 16:16:50 +00:00
CGDebugInfo.h Substantially alter the design of the Objective C type AST by introducing 2010-05-15 11:32:37 +00:00
CGDecl.cpp Change EmitReferenceBindingToExpr to take a decl instead of a boolean. 2010-06-26 16:35:32 +00:00
CGDeclCXX.cpp Change EmitReferenceBindingToExpr to take a decl instead of a boolean. 2010-06-26 16:35:32 +00:00
CGException.cpp Fix personality function name when using SjLj exceptions. 2010-05-28 19:43:36 +00:00
CGExpr.cpp Implement rdar://7530813 - collapse multiple GEP instructions in IRgen 2010-06-26 23:03:20 +00:00
CGExprAgg.cpp Change EmitReferenceBindingToExpr to take a decl instead of a boolean. 2010-06-26 16:35:32 +00:00
CGExprCXX.cpp Minor change to my last patch to fix PR7490. 2010-06-25 20:01:13 +00:00
CGExprComplex.cpp Code gen for compound assignment of complex 2010-03-23 18:43:00 +00:00
CGExprConstant.cpp use more efficient type comparison predicates. 2010-06-26 21:52:32 +00:00
CGExprScalar.cpp fix inc/dec to honor -fwrapv and -ftrapv, implementing PR7426. 2010-06-26 22:18:28 +00:00
CGObjC.cpp Fix an Obj-C++ miscompile when calling an Obj-C method that returns a C++ reference. 2010-06-21 20:59:55 +00:00
CGObjCGNU.cpp Objective-c++ IRGen. Support for @selector expression as 2010-06-17 19:56:20 +00:00
CGObjCMac.cpp Type Type::isRealFloatingType() that vectors are not floating-point 2010-06-22 23:07:26 +00:00
CGObjCRuntime.h Objective-c++ IRGen. Support for @selector expression as 2010-06-17 19:56:20 +00:00
CGRTTI.cpp When building RTTI descriptors for pointer types, we need to get the unqualified array type and the qualifiers from it. 2010-06-02 15:44:35 +00:00
CGRecordLayout.h Keep track of the LLVM field numbers for non-virtual bases. 2010-05-18 05:22:06 +00:00
CGRecordLayoutBuilder.cpp AST: Rename PragmaPackAttr to MaxFieldAlignmentAttr, which is more accurate. 2010-05-27 01:12:46 +00:00
CGStmt.cpp Change EmitReferenceBindingToExpr to take a decl instead of a boolean. 2010-06-26 16:35:32 +00:00
CGTemporaries.cpp Add the same 'ForVirtualBase' parameter to EmitCXXDestructorCall. 2010-05-02 23:29:11 +00:00
CGVTT.cpp The global variable for the VTT might not have external linkage; allow 2010-05-06 22:18:21 +00:00
CGVTables.cpp Make sure to set the visible on a vtable; VTTs and typeinfo already 2010-06-14 23:41:45 +00:00
CGVTables.h Don't try to emit the vtable for a class just because we're emitting a 2010-06-02 21:22:02 +00:00
CGValue.h CodeGen: Shrink RValue. 4 words -> 2 words. 2010-05-02 14:59:10 +00:00
CMakeLists.txt Update CMake build for new attribute changes. 2010-06-17 00:37:02 +00:00
CodeGenAction.cpp Break Frontend's dependency on Rewrite, Checker and CodeGen in shared library configuration 2010-06-15 17:48:49 +00:00
CodeGenFunction.cpp Change IR generation for return (in the simple case) to avoid doing silly 2010-06-27 01:06:27 +00:00
CodeGenFunction.h Change IR generation for return (in the simple case) to avoid doing silly 2010-06-27 01:06:27 +00:00
CodeGenModule.cpp Patch to correctly mangle block helper functions 2010-06-24 00:08:06 +00:00
CodeGenModule.h Patch to correctly mangle block helper functions 2010-06-24 00:08:06 +00:00
CodeGenTypes.cpp Fix for PR7040: Don't try to compute the LLVM type for a function where it 2010-05-30 06:03:20 +00:00
CodeGenTypes.h Fix for PR7040: Don't try to compute the LLVM type for a function where it 2010-05-30 06:03:20 +00:00
GlobalDecl.h Add GlobalDecl::getCanonicalDecl. 2010-06-22 16:00:14 +00:00
ItaniumCXXABI.cpp IRgen: Add a stub class for generating ABI-specific C++ code. 2010-05-25 19:52:27 +00:00
Makefile Makefiles: Set Clang CPP compiler flags in a single location, instead of scattered throughout the project Makefiles. 2010-06-08 20:44:43 +00:00
Mangle.cpp Add function for mangling reference temporaries. 2010-06-26 16:09:40 +00:00
Mangle.h Add function for mangling reference temporaries. 2010-06-26 16:09:40 +00:00
MicrosoftCXXABI.cpp Mangle pointer and (lvalue) reference types in the Microsoft C++ Mangler. 2010-06-26 03:50:05 +00:00
ModuleBuilder.cpp Move CodeGenOptions.h *back* into Frontend. This should have been done when the 2010-06-15 23:19:56 +00:00
README.txt These IRgen improvements have been done. 2009-07-23 03:03:07 +00:00
TargetInfo.cpp use more efficient type comparison predicates. 2010-06-26 21:52:32 +00:00
TargetInfo.h Implement __builtin_dwarf_sp_column for i386 (Darwin and not), x86-64 (all), 2010-03-06 00:35:14 +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!

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