From ee52b6e77db149b4a256ed0f993499f2bb093e20 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 14 Mar 2016 20:18:59 +0000 Subject: allow branch weight metadata on select instructions (PR26636) As noted in: https://llvm.org/bugs/show_bug.cgi?id=26636 This doesn't accomplish anything on its own. It's the first step towards preserving and using branch weights with selects. The next step would be to make sure we're propagating the info in all of the other places where we create selects (SimplifyCFG, InstCombine, etc). I don't think there's an easy fix to make this happen; we have to look at each transform individually to determine how to correctly propagate the weights. Along with that step, we need to then use the weights when making subsequent transform decisions such as discussed in http://reviews.llvm.org/D16836. The inliner test is independent but closely related. It verifies that metadata is preserved when both branches and selects are cloned. Differential Revision: http://reviews.llvm.org/D18133 llvm-svn: 263482 --- llvm/test/Transforms/Inline/profile-meta.ll | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 llvm/test/Transforms/Inline/profile-meta.ll (limited to 'llvm/test/Transforms/Inline') diff --git a/llvm/test/Transforms/Inline/profile-meta.ll b/llvm/test/Transforms/Inline/profile-meta.ll new file mode 100644 index 00000000000..5000b83f2f3 --- /dev/null +++ b/llvm/test/Transforms/Inline/profile-meta.ll @@ -0,0 +1,41 @@ +; RUN: opt < %s -S -inline | FileCheck %s + +; Make sure that profile metadata is preserved when cloning a select. + +define i32 @callee_with_select(i1 %c, i32 %a, i32 %b) { + %sel = select i1 %c, i32 %a, i32 %b, !prof !0 + ret i32 %sel +} + +define i32 @caller_of_select(i1 %C, i32 %A, i32 %B) { + %ret = call i32 @callee_with_select(i1 %C, i32 %A, i32 %B) + ret i32 %ret + +; CHECK-LABEL: @caller_of_select( +; CHECK-NEXT: [[SEL:%.*]] = select i1 %C, i32 %A, i32 %B, !prof !0 +; CHECK-NEXT: ret i32 [[SEL]] +} + +; Make sure that profile metadata is preserved when cloning a branch. + +define i32 @callee_with_branch(i1 %c) { + br i1 %c, label %if, label %else, !prof !1 +if: + ret i32 1 +else: + ret i32 2 +} + +define i32 @caller_of_branch(i1 %C) { + %ret = call i32 @callee_with_branch(i1 %C) + ret i32 %ret + +; CHECK-LABEL: @caller_of_branch( +; CHECK-NEXT: br i1 %C, label %{{.*}}, label %{{.*}}, !prof !1 +} + +!0 = !{!"branch_weights", i32 1, i32 2} +!1 = !{!"branch_weights", i32 3, i32 4} +; CHECK: !0 = !{!"branch_weights", i32 1, i32 2} +; CHECK: !1 = !{!"branch_weights", i32 3, i32 4} + -- cgit v1.2.3