[llvm] r267624 - [SimplifyCFG] propagate branch metadata when creating select

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 16:15:48 PDT 2016


Author: spatel
Date: Tue Apr 26 18:15:48 2016
New Revision: 267624

URL: http://llvm.org/viewvc/llvm-project?rev=267624&view=rev
Log:
[SimplifyCFG] propagate branch metadata when creating select


Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=267624&r1=267623&r2=267624&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Apr 26 18:15:48 2016
@@ -1220,7 +1220,7 @@ HoistTerminator:
       if (!SI)
         SI = cast<SelectInst>
           (Builder.CreateSelect(BI->getCondition(), BB1V, BB2V,
-                                BB1V->getName() + "." + BB2V->getName()));
+                                BB1V->getName() + "." + BB2V->getName(), BI));
 
       // Make the PHI node use the select for all incoming values for BB1/BB2
       for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)

Modified: llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll?rev=267624&r1=267623&r2=267624&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll Tue Apr 26 18:15:48 2016
@@ -387,6 +387,31 @@ for.exit:
   ret void
 }
 
+; Don't drop the metadata.
+
+define i32 @HoistThenElseCodeToIf(i32 %n) {
+; CHECK-LABEL: @HoistThenElseCodeToIf(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp eq i32 %n, 0
+; CHECK-NEXT:    [[DOT:%.*]] = select i1 [[TOBOOL]], i32 1, i32 234, !prof !11
+; CHECK-NEXT:    ret i32 [[DOT]]
+;
+entry:
+  %tobool = icmp eq i32 %n, 0
+  br i1 %tobool, label %if, label %else, !prof !0
+
+if:
+  br label %return
+
+else:
+  br label %return
+
+return:
+  %retval.0 = phi i32 [ 1, %if ], [ 234, %else ]
+  ret i32 %retval.0
+}
+
+
 !0 = !{!"branch_weights", i32 3, i32 5}
 !1 = !{!"branch_weights", i32 1, i32 1}
 !2 = !{!"branch_weights", i32 1, i32 2}
@@ -406,7 +431,7 @@ for.exit:
 ; CHECK: !2 = !{!"branch_weights", i32 7, i32 1, i32 2}
 ; CHECK: !3 = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
 ; CHECK: !4 = !{!"branch_weights", i32 11, i32 5}
-; CHECK: !5 = !{!"branch_weights", i32 17, i32 15} 
+; CHECK: !5 = !{!"branch_weights", i32 17, i32 15}
 ; CHECK: !6 = !{!"branch_weights", i32 9, i32 7}
 ; CHECK: !7 = !{!"branch_weights", i32 17, i32 9, i32 8, i32 7, i32 17}
 ; CHECK: !8 = !{!"branch_weights", i32 24, i32 33}
@@ -414,3 +439,5 @@ for.exit:
 ;; The false weight prints out as a negative integer here, but inside llvm, we
 ;; treat the weight as an unsigned integer.
 ; CHECK: !10 = !{!"branch_weights", i32 112017436, i32 -735157296}
+; CHECK: !11 = !{!"branch_weights", i32 3, i32 5}
+




More information about the llvm-commits mailing list