Author: Hiroshi Yamauchi Date: 2020-01-23T00:47:18+01:00 New Revision: b5cdee9bdce49b31c74b0cf4f8231f66bbc2708e
URL: https://github.com/llvm/llvm-project/commit/b5cdee9bdce49b31c74b0cf4f8231f66bbc2708e DIFF: https://github.com/llvm/llvm-project/commit/b5cdee9bdce49b31c74b0cf4f8231f66bbc2708e.diff LOG: [PGO][PGSO] Update BFI in CodeGenPrepare::optimizeSelectInst. Summary: Without the BFI update, some hot blocks are incorrectly treated as cold code. This fixes a FDO perf regression in the TSVC benchmark from D71288. Reviewers: davidxl Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73146 (cherry picked from commit ddbc728828c70728473b47c9f7427aa9514f3d17) Added: Modified: llvm/lib/CodeGen/CodeGenPrepare.cpp llvm/test/CodeGen/X86/cmov-into-branch.ll Removed: ################################################################################ diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index f05afd058746..003db39fe5f9 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -6122,6 +6122,7 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) { BasicBlock *StartBlock = SI->getParent(); BasicBlock::iterator SplitPt = ++(BasicBlock::iterator(LastSI)); BasicBlock *EndBlock = StartBlock->splitBasicBlock(SplitPt, "select.end"); + BFI->setBlockFreq(EndBlock, BFI->getBlockFreq(StartBlock).getFrequency()); // Delete the unconditional branch that was just created by the split. StartBlock->getTerminator()->eraseFromParent(); diff --git a/llvm/test/CodeGen/X86/cmov-into-branch.ll b/llvm/test/CodeGen/X86/cmov-into-branch.ll index 6cc81ac0833b..d9ab2550f791 100644 --- a/llvm/test/CodeGen/X86/cmov-into-branch.ll +++ b/llvm/test/CodeGen/X86/cmov-into-branch.ll @@ -165,6 +165,30 @@ define i32 @weighted_select_pgso(i32 %a, i32 %b) !prof !14 { ret i32 %sel } +; If two selects in a row are predictable, turn them into branches. +define i32 @weighted_selects(i32 %a, i32 %b) !prof !19 { +; CHECK-LABEL: weighted_selects: +; CHECK: # %bb.0: +; CHECK-NEXT: movl %esi, %eax +; CHECK-NEXT: testl %edi, %edi +; CHECK-NEXT: movl %edi, %ecx +; CHECK-NEXT: jne .LBB11_2 +; CHECK-NEXT: # %bb.1: # %select.false +; CHECK-NEXT: movl %eax, %ecx +; CHECK-NEXT: .LBB11_2: # %select.end +; CHECK-NEXT: testl %ecx, %ecx +; CHECK-NEXT: jne .LBB11_4 +; CHECK-NEXT: # %bb.3: # %select.false2 +; CHECK-NEXT: movl %edi, %eax +; CHECK-NEXT: .LBB11_4: # %select.end1 +; CHECK-NEXT: retq + %cmp = icmp ne i32 %a, 0 + %sel = select i1 %cmp, i32 %a, i32 %b, !prof !16 + %cmp1 = icmp ne i32 %sel, 0 + %sel1 = select i1 %cmp1, i32 %b, i32 %a, !prof !16 + ret i32 %sel1 +} + !llvm.module.flags = !{!0} !0 = !{i32 1, !"ProfileSummary", !1} !1 = !{!2, !3, !4, !5, !6, !7, !8, !9} @@ -185,3 +209,4 @@ define i32 @weighted_select_pgso(i32 %a, i32 %b) !prof !14 { !16 = !{!"branch_weights", i32 1, i32 100} !17 = !{!"branch_weights", i32 100, i32 1} !18 = !{!"branch_weights", i32 0, i32 0} +!19 = !{!"function_entry_count", i64 100} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits