Skip to content

Commit

Permalink
[SimplifyCFG] propagate branch metadata when creating select (PR26636)
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264527 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rotateright committed Mar 26, 2016
1 parent 992a592 commit cdc2723
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,8 +1642,8 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
Value *FalseV = SpeculatedStoreValue;
if (Invert)
std::swap(TrueV, FalseV);
Value *S = Builder.CreateSelect(BrCond, TrueV, FalseV, TrueV->getName() +
"." + FalseV->getName());
Value *S = Builder.CreateSelect(
BrCond, TrueV, FalseV, TrueV->getName() + "." + FalseV->getName(), BI);
SpeculatedStore->setOperand(0, S);
}

Expand Down
7 changes: 5 additions & 2 deletions test/Transforms/SimplifyCFG/speculate-store.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ define void @ifconvertstore(i32* %A, i32 %B, i32 %C, i32 %D) {
; CHECK-LABEL: @ifconvertstore(
; CHECK: store i32 %B, i32* %A
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %D, 42
; CHECK-NEXT: [[C_B:%.*]] = select i1 [[CMP]], i32 %C, i32 %B
; CHECK-NEXT: [[C_B:%.*]] = select i1 [[CMP]], i32 %C, i32 %B, !prof !0
; CHECK-NEXT: store i32 [[C_B]], i32* %A
; CHECK-NEXT: ret void
;
entry:
; First store to the location.
store i32 %B, i32* %A
%cmp = icmp sgt i32 %D, 42
br i1 %cmp, label %if.then, label %ret.end
br i1 %cmp, label %if.then, label %ret.end, !prof !0

; Make sure we speculate stores like the following one. It is cheap compared to
; a mispredicated branch.
Expand Down Expand Up @@ -85,3 +85,6 @@ ret.end:
ret void
}

; CHECK: !0 = !{!"branch_weights", i32 3, i32 5}
!0 = !{!"branch_weights", i32 3, i32 5}

0 comments on commit cdc2723

Please sign in to comment.