[PATCH] D73146: [PGO][PGSO] Update BFI in CodeGenPrepare::optimizeSelectInst.

Hiroshi Yamauchi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 08:41:14 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGddbc728828c7: [PGO][PGSO] Update BFI in CodeGenPrepare::optimizeSelectInst. (authored by yamauchi).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73146/new/

https://reviews.llvm.org/D73146

Files:
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/test/CodeGen/X86/cmov-into-branch.ll


Index: llvm/test/CodeGen/X86/cmov-into-branch.ll
===================================================================
--- llvm/test/CodeGen/X86/cmov-into-branch.ll
+++ llvm/test/CodeGen/X86/cmov-into-branch.ll
@@ -165,6 +165,30 @@
   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 @@
 !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}
Index: llvm/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -6138,6 +6138,7 @@
   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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73146.239613.patch
Type: text/x-patch
Size: 1987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200122/e3dd0c95/attachment.bin>


More information about the llvm-commits mailing list