gcc编译优化选项-O[s123g]_sharemon的博客-程序员秘密

技术标签: 编译  

看了一个知乎的问题,感觉比较下面的回答讲的比较全面,收录整理一下,侵删。

gcc编译优化选项

-O0: This level (that is the letter “O” followed by a zero) turns off optimization entirely and is the default if no -O level is specified in CFLAGS or CXXFLAGS. This reduces compilation time and can improve debugging info, but some applications will not work properly without optimization enabled. This option is not recommended except for debugging purposes.

-O1: the most basic optimization level. The compiler will try to produce faster, smaller code without taking much compilation time. It is basic, but it should get the job done all the time.

-O2: A step up from -O1. The recommended level of optimization unless the system has special needs. -O2 will activate a few more flags in addition to the ones activated by -O1. With -O2, the compiler will attempt to increase code performance without compromising on size, and without taking too much compilation time. O2会开启大部分应用都支持的优化选项,而O3开启的则多为向量化优化选项 ,提高对并行执行的支持

-O3: the highest level of optimization possible. It enables optimizations that are expensive in terms of compile time and memory usage. Compiling with -O3 is not a guaranteed way to improve performance, and in fact, in many cases, can slow down a system due to larger binaries and increased memory usage. -O3 is also known to break several packages. Using -O3 is not recommended.(也有回答说,一般release版本都用O3优化。个人感觉如果O3可以过产品测试,就应该用O3,当然前提是保证你的程序size不会过大。size过大也可以配合使用noinline)

-Os: optimizes code for size. It activates all -O2 options that do not increase the size of the generated code. It can be useful for machines that have extremely limited disk storage space and/or CPUs with small cache sizes.

-Og: In GCC 4.8, a new general optimization level, -Og, has been introduced. It addresses the need for fast compilation and a superior debugging experience while providing a reasonable level of runtime performance. Overall experience for development should be better than the default optimization level -O0. Note that -Og does not imply -g, it simply disables optimizations that may interfere with debugging.

-Ofast: New in GCC 4.7, consists of -O3 plus -ffast-math, -fno-protect-parens, and -fstack-arrays. This option breaks strict standards compliance, and is not recommended for use.

O123都开启了哪些选项

对于每一个选项的解释:Options That Control Optimization

O1:
-fauto-inc-dec
-fbranch-count-reg
-fcombine-stack-adjustments
-fcompare-elim
-fcprop-registers
-fdce
-fdefer-pop
-fdelayed-branch
-fdse
-fforward-propagate
-fguess-branch-probability
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-fipa-profile
-fipa-pure-const
-fipa-reference
-fipa-reference-addressable
-fmerge-constants
-fmove-loop-invariants
-fomit-frame-pointer
-freorder-blocks
-fshrink-wrap
-fshrink-wrap-separate
-fsplit-wide-types
-fssa-backprop
-fssa-phiopt
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-coalesce-vars
-ftree-copy-prop
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-forwprop
-ftree-fre
-ftree-phiprop
-ftree-pta
-ftree-scev-cprop
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-ter
-funit-at-a-time

O2:
-falign-functions -falign-jumps
-falign-labels -falign-loops
-fcaller-saves
-fcode-hoisting
-fcrossjumping
-fcse-follow-jumps -fcse-skip-blocks
-fdelete-null-pointer-checks
-fdevirtualize -fdevirtualize-speculatively
-fexpensive-optimizations
-ffinite-loops
-fgcse -fgcse-lm
-fhoist-adjacent-loads
-finline-functions
-finline-small-functions
-findirect-inlining
-fipa-bit-cp -fipa-cp -fipa-icf
-fipa-ra -fipa-sra -fipa-vrp
-fisolate-erroneous-paths-dereference
-flra-remat
-foptimize-sibling-calls
-foptimize-strlen
-fpartial-inlining
-fpeephole2
-freorder-blocks-algorithm=stc
-freorder-blocks-and-partition -freorder-functions
-frerun-cse-after-loop
-fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec
-fstore-merging
-fstrict-aliasing
-fthread-jumps
-ftree-builtin-call-dce
-ftree-pre
-ftree-switch-conversion -ftree-tail-merge
-ftree-vrp

O3:
-fgcse-after-reload
-fipa-cp-clone
-floop-interchange
-floop-unroll-and-jam
-fpeel-loops
-fpredictive-commoning
-fsplit-paths
-ftree-loop-distribute-patterns
-ftree-loop-distribution
-ftree-loop-vectorize
-ftree-partial-pre
-ftree-slp-vectorize
-funswitch-loops
-fvect-cost-model
-fversion-loops-for-strides

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sharemon/article/details/104377527

智能推荐

激光打标机的特性及应用范围_cky2629的博客-程序员秘密

杭州七琴激光打标机坐落在美丽的杭州,拥有进口、国产激光打标机、切割机,专业激光打标加工技术,3年的激光经验,丰富的花样图案,熟练的设计\操作人员,可根据客户要求开发各种花纹图案。 下面杭州七琴激光打标将详细介绍...

hdoj 2077汉诺塔IV_Calm微笑的博客-程序员秘密

汉诺塔IVTime Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5540    Accepted Submission(s): 3998Problem Description还记得汉诺塔III吗?他的规则是这样的:不允许直

Android 状态栏关于开发的几件事_chuanao8829的博客-程序员秘密

最近手头做了一个新的项目,开发中对状态栏的要求比较多,也作了一些总结,分享给大家。   简答题 全屏、不保留状态栏文字(Splash页面,欢迎页面) 全屏保留状态栏文字(页面上部有Banner图) 标题栏与状态栏颜色一致(部分App风格) 不同Fragment中对Sta...

iOS开发-nil/Nil/NULL/NSNull 的使用_ios开发 nsnull_Pandakingli的博客-程序员秘密

nil: A null pointer to an Objective-C object. ( #define nil ((id)0) ) nil 是一个对象值。Nil: A null pointer to an Objective-C class.NULL: A null pointer to anything else. ( #define NULL ((void *)0) ) NU

机器学习-周志华-课后习题答案-决策树_试编程实现基于信息熵进行划分选择的决策树算法,并为表4.3中数据生成一棵决策树_天台的猫爷爷的博客-程序员秘密

4.1试证明对于不含冲突数据(即特征向量完全相同但标记不同)的训练集,必存在与训练集一致(即训练误差为0)的决策树答:假设不存在与训练集一致的决策树,那么训练集训练得到的决策树至少有一个节点上存在无法划分的多个数据(若节点上没有冲突数据,那么总是能够将数据分开的)。这与前提-不含冲突数据 矛盾,因此必存在与训练集一致的决策树 4.2试析使用“最小训练误差”作为决策树划分选择的缺陷。答:若以最小训练

Centos 7 安装MySQL_centos7安装mysql_Serendipity_lll的博客-程序员秘密

一、利用 Yum Repository来安装,Mysql版本5.7.14 yum -y install mysql57-community-release-el7-10.noarch.rpm如果出现No package错误这是因为我们本地yum仓库中没有可用的mysql-server rpm包。这时可执行以下命令:wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm接着就开始安装MySQL

随便推点

【LeetCode】556. 下一个更大元素 III_fuqiuai的博客-程序员秘密

题目链接:https://leetcode-cn.com/problems/next-greater-element-iii/description/题目描述给定一个32位正整数 n,你需要找到最小的32位整数,其与 n 中存在的位数完全相同,并且其值大于n。如果不存在这样的32位整数,则返回-1。示例输入: 12输出: 21输入: 21输出: -1解决方法将n中每一位取出存入v...

java批量导出数据到excel表格_程序员张三的博客-程序员秘密

java批量导出数据到excel使用hutool中的导出工具1. 需要的依赖<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.0.7</version></dependency><dependency> <groupId>

java编写程序输出1-100之间所有既是5又是7的倍数的数_1、定义一个方法Bs( ),其作用为输出1-100之间指定数字n的倍数,每行输出10个数字 2、在main( )方法中调用方法Bs( )两..._哈影小十君的博客-程序员秘密

【简答题】要求创建一个整型数组 a ,长度为 10 ,利用循环给数组元素赋值为前 10 个偶数,即 2 , 4 , 6 , 8 , ...18 , 20. 再 将数组元素的值顺序输出。【其它】编程题: 1、 编写1个Java程序“Task5_1.java”,要求用户输入姓名、年龄、性别、身高并以特定格式输出。 将代码拍照上传(照片中要出现自己的2位学号及姓名) 提示: 1 )姓名为字符串 2...

使用AlarmManager服务设置闹钟_alarmmanager 闹铃和震动_u010142437的博客-程序员秘密

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)AlarmManage通常的用途就是用来开发手机闹钟,但它的作用不止于此。它的本质是一个全局的定时器,可在指定时间或指定周期启动其他组件。我们可以调用AlarmManage的如下方法来设置定时启动指定组件:...

纯CSS select 下拉框美化_select 美化css_天迹Ray的博客-程序员秘密

<style>body { font-size: 20px; color: #090; background-color: #eee; text-align: center; } .select { display: inline-block; width: 300px; position: relative; vertical-align: middle; padding: 0; overflow: hidden; background-co.

typora导出HTML或者PDF内容缺失_typora导出pdf少内容_二木成林的博客-程序员秘密

错误typora导出HTML或者PDF,内容缺失,目录无法索引的链接位置。导出HTML查看源码,源码有内容但是无法显示出来。原因由于大多数人使用typora都是程序员,涉及到很多代码,特别是前端代码。如果markdown内容中有<script></script>等标签就会造成源码的标签错误。导致导出的HTML出现内容缺失,但是源码仍然存在。解决...

推荐文章

热门文章

相关标签