compiler-optimization

When can Hotspot allocate objects on the stack? [duplicate]

只愿长相守 提交于 2019-12-17 10:34:41
问题 This question already has answers here : Eligibility for escape analysis / stack allocation with Java 7 (3 answers) Closed 2 years ago . Since somewhere around Java 6, the Hotspot JVM can do escape analysis and allocate non-escaping objects on the stack instead of on the garbage collected heap. This results in a speedup of the generated code and reduces pressure on the garbage collector. What are the rules for when Hotspot is able to stack allocate objects? In other words when can I rely on

LTO, Devirtualization, and Virtual Tables

孤街醉人 提交于 2019-12-17 09:41:57
问题 Comparing virtual functions in C++ and virtual tables in C, do compilers in general (and for sufficiently large projects) do as good a job at devirtualization? Naively, it seems like virtual functions in C++ have slightly more semantics, thus may be easier to devirtualize. Update: Mooing Duck mentioned inlining devirtualized functions. A quick check shows missed optimizations with virtual tables: struct vtab { int (*f)(); }; struct obj { struct vtab *vtab; int data; }; int f() { return 5; }

LTO, Devirtualization, and Virtual Tables

六眼飞鱼酱① 提交于 2019-12-17 09:41:25
问题 Comparing virtual functions in C++ and virtual tables in C, do compilers in general (and for sufficiently large projects) do as good a job at devirtualization? Naively, it seems like virtual functions in C++ have slightly more semantics, thus may be easier to devirtualize. Update: Mooing Duck mentioned inlining devirtualized functions. A quick check shows missed optimizations with virtual tables: struct vtab { int (*f)(); }; struct obj { struct vtab *vtab; int data; }; int f() { return 5; }

GCC(/Clang): Merging functions with identical instructions (COMDAT folding)

独自空忆成欢 提交于 2019-12-17 05:02:35
问题 Just curious, do the GCC or Clang toolsets implement the equivalent of MSVC's identical COMDAT folding (ICF) currently? If not, are there any plans to? I can't seem to find any recent authoritative links on the subject other than old GCC mailing list messages. If not, does this imply that template instantiations over distinct types are always distinct functions in the resulting binary (in situations where they are not completely inlined), even when they are binary-compatible, or are there

C optimisation of string literals

旧时模样 提交于 2019-12-17 02:37:51
问题 just been inspecting the following in gdb: char *a[] = {"one","two","three","four"}; char *b[] = {"one","two","three","four"}; char *c[] = {"two","three","four","five"}; char *d[] = {"one","three","four","six"}; and i get the following: (gdb) p a $17 = {0x80961a4 "one", 0x80961a8 "two", 0x80961ac "three", 0x80961b2 "four"} (gdb) p b $18 = {0x80961a4 "one", 0x80961a8 "two", 0x80961ac "three", 0x80961b2 "four"} (gdb) p c $19 = {0x80961a8 "two", 0x80961ac "three", 0x80961b2 "four", 0x80961b7

Functions only getting inlined if defined in a header. Am I missing something?

谁都会走 提交于 2019-12-14 03:52:19
问题 Using gcc v4.8.1 If I do: //func.hpp #ifndef FUNC_HPP #define FUNC_HPP int func(int); #endif //func.cpp #include "func.hpp" int func(int x){ return 5*x+7; } //main.cpp #include <iostream> #include "func.hpp" using std::cout; using std::endl; int main(){ cout<<func(5)<<endl; return 0; } Even the simple function func will not get inlined. No combination of inline , extern , static , and __attribute__((always_inline)) on the prototype and/or the definition changes this (obviously some

Avoid optimizing away variable with inline asm

主宰稳场 提交于 2019-12-14 03:49:13
问题 I was reading Preventing compiler optimizations while benchmarking that describes how clobber() and escape() from Chandler Carruths talk CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" affects the compiler. From reading that, I assumed that if I have an input constraint like "g"( val ), then the compiler wouldn't be able to optimize away val . But in g() below, no code is generated. Why? How can doNotOptimize() be rewritten to ensure code is generated

How does GCC store member functions in memory?

*爱你&永不变心* 提交于 2019-12-14 03:37:54
问题 I am trying to minimise the size my class occupies in memory (both data and instructions). I know how to minimise data size, but I am not too familiar with how GCC places member functions. Are they stored in memory, the same order they are declared in the class? 回答1: For the purpose of in-memory data representation, a C++ class can have either plain or static member functions, or virtual member functions (including some virtual destructor, if any). Plain or static member functions do not take

Can AVX2-compiled program still use 32 registers of an AVX-512 capable CPU?

陌路散爱 提交于 2019-12-14 01:28:09
问题 Assuming AVX2-targeted compilation and with C++ intrinsics, if I write an nbody algorithm using 17 registers per body-body computation, can 17th register be indirectly(register rename hardware) or directly(visual studio compiler, gcc compiler) be mapped on an AVX-512 register to cut memory dependency off? For example, skylake architecture has 1 or 2 AVX-512 fma units. Does this number change total registers available too? (specifically, a xeon silver 4114 cpu) If this works, how does it work?

Does volatile prevent introduced reads or writes?

左心房为你撑大大i 提交于 2019-12-14 00:21:50
问题 In C#, volatile keyword ensures that reads and writes have acquire and release semantics, respectively. However, does it say anything about introduced reads or writes? For instance: volatile Thing something; volatile int aNumber; void Method() { // Are these lines... var local = something; if (local != null) local.DoThings(); // ...guaranteed not to be transformed into these by compiler, jitter or processor? if (something != null) something.DoThings(); // <-- Second read! // Are these lines..