CompilerDev 板


LINE

大家好, 最近發現 llvm ir 有一個 attribute 叫做 frame-pointer, 它會影響 performance 目前 O3 預設是 none 的, 而如果是用 clang -emit-llvm -Xclang -disable-O0-optnone 這樣的方式取得沒有優化過的 llvm ir,則會是 all 據我說知,他會消除 frame pointer 的儲存(如果是 none 的話), "理論上"會讓程式的 performance 好一點,畢竟會減少 register 的使用 經過測試,確實如果同是使用 O3 sequence,frame-pointer=none performance確實比較好 但是!! 我用我自己的優化順序, frame-pointer=none 得到的 runtime = 8 sec 左右 frame-pointer=all 得到的 runtime = 3.8 sec 差非常多! 然後我把他們轉成 Assembly code,確實不太一樣, 但 none 程式碼比較短,而且減少很多存取 卻讓 performance 更差勁 可以明白指令的多寡與 performance 無關, 但據我說知,frame-pointer 不去儲存與使用,應該會更快吧? 甚至我自己有些 IR 從 all 改 none 會更好 唯獨某幾個 IR code 會更差。 我測試的 source code 的是 insertion sort https://imgur.com/nqexaZb https://imgur.com/hKigtrh https://imgur.com/FR3qETS https://imgur.com/5119ek8 https://imgur.com/g3RHx98 這些是 Assembly code 的差異, 感覺與 insertion sort 本身的邏輯無關 補上 perf 之後的結果: frame-pointer=all Performance counter stats for './190_all' (10 runs): 142666 cache-misses # 0.020 % of all cache refs ( +- 5.01% ) 698701320 cache-references ( +- 0.71% ) 234781 branch-misses ( +- 0.44% ) 13059296783 cycles ( +- 0.16% ) 59991967735 instructions # 4.59 insn per cycle ( +- 0.05% ) 3.417880975 seconds time elapsed ( +- 0.26% ) frame-pointer=none Performance counter stats for './190_none' (10 runs): 352932 cache-misses # 0.046 % of all cache refs ( +- 2.58% ) 770977710 cache-references ( +- 0.81% ) 260282 branch-misses ( +- 0.33% ) 30052057516 cycles ( +- 0.05% ) 60037013675 instructions # 2.00 insn per cycle ( +- 0.05% ) 7.921856465 seconds time elapsed ( +- 0.05% ) 看起來branch-misses 高大概10% Insn per cycle 直接慢一半.. --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.59.118 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/CompilerDev/M.1636380668.A.B00.html
1F:推 sonicyang: runetime 比較短performance 比較差?我漏看了什麼嗎 ? 11/09 00:50
抱歉,我秒數弄錯了
2F:→ Lipraxde: Assembly 都在你眼前了,再加點油分析一下。 11/09 01:55
3F:→ Lipraxde: LLVM 可以在每個 pass 跑完後 dump IR / machine IR,11/09 01:55
4F:→ Lipraxde: 對了解優化、為什麼生出這樣的 pattern 很有幫助。11/09 01:55
5F:→ Lipraxde: 另外就是不太確定你有沒有讀過 System V ABI,如果要做11/09 01:55
6F:→ Lipraxde: 的這麼深的優化的話熟悉 ABI 是很重要的!11/09 01:55
7F:→ Lipraxde: 啊...好像講了些不太相干的東西,回到你的問題,雖然給11/09 02:04
8F:→ Lipraxde: 的資訊有點少,不過從執行時間的差距、codegen 結果的11/09 02:04
9F:→ Lipraxde: 差異來看,我會覺得有可能是由於 cache 所造成的。11/09 02:04
剛剛使用 Linux 的工具 perf 分析兩者差異, 在 cache misses, cache reference 上沒有差異, 但在 instrcutions per cycle 上有著顯著的差異: frame-pointer=all 的 有 4.56 instruction num per cycles, frame-pointer=none 的則只有 1.99 instruction num per cycles. ※ 編輯: shane87123 (114.43.59.118 臺灣), 11/09/2021 02:17:11 ※ 編輯: shane87123 (114.43.59.118 臺灣), 11/09/2021 02:32:19
10F:→ Lipraxde: Branch miss 呢?11/09 09:19
補上了!謝謝大大 ※ 編輯: shane87123 (101.12.89.21 臺灣), 11/09/2021 13:28:27 ※ 編輯: shane87123 (101.12.89.21 臺灣), 11/09/2021 13:28:51
11F:→ Lipraxde: 有開 frame-pointer 的版本因為有多的 push、move 個關 11/09 16:50
12F:→ Lipraxde: 係,因此不建議直接對 instruction num per cycles 下 11/09 16:50
13F:→ Lipraxde: 定論。然後我注意到一個地方,all、none 的 instructio 11/09 16:50
14F:→ Lipraxde: n 數量是差不多的,可以看看是為什麼 :) 11/09 16:50







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:WOW站內搜尋

TOP