summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms
diff options
context:
space:
mode:
authorYevgeny Rouban <yevgeny.rouban@azul.com>2019-06-05 05:46:40 +0000
committerYevgeny Rouban <yevgeny.rouban@azul.com>2019-06-05 05:46:40 +0000
commita3e16719c46aff109a6902c32787c06831c0e61d (patch)
treee32e338790f39c374724f86a54eab43849f5ee24 /llvm/test/Transforms
parentfa449a9bb27abdc43a4dbd17dc84d920f5f408d8 (diff)
downloadbcm5719-llvm-a3e16719c46aff109a6902c32787c06831c0e61d.tar.gz
bcm5719-llvm-a3e16719c46aff109a6902c32787c06831c0e61d.zip
Resubmit "[CorrelatedValuePropagation] Fix prof branch_weights metadata handling for SwitchInst"
This reverts commit 5b32f60ec31ce136edac6f693538aeb6039f4ad0. The fix is in commit 4f9e68148bd0dada2d6997625432385918ac2e2c. This patch fixes the CorrelatedValuePropagation pass to keep prof branch_weights metadata of SwitchInst consistent. It makes use of SwitchInstProfUpdateWrapper. New tests are added. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D62126 llvm-svn: 362583
Diffstat (limited to 'llvm/test/Transforms')
-rw-r--r--llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll119
1 files changed, 119 insertions, 0 deletions
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll b/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll
new file mode 100644
index 00000000000..493b4c2273e
--- /dev/null
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/profmd.ll
@@ -0,0 +1,119 @@
+; RUN: opt < %s -correlated-propagation -S | FileCheck %s
+
+; Removed several cases from switch.
+define i32 @switch1(i32 %s) {
+; CHECK-LABEL: @switch1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[S:%.*]], 0
+; CHECK-NEXT: br i1 [[CMP]], label [[NEGATIVE:%.*]], label [[OUT:%.*]]
+;
+entry:
+ %cmp = icmp slt i32 %s, 0
+ br i1 %cmp, label %negative, label %out
+
+negative:
+; CHECK: negative:
+; CHECK-NEXT: switch i32 [[S]], label [[OUT]] [
+; CHECK-NEXT: i32 -2, label [[NEXT:%.*]]
+; CHECK-NEXT: i32 -1, label [[NEXT]]
+ switch i32 %s, label %out [
+ i32 0, label %out
+ i32 1, label %out
+ i32 -1, label %next
+ i32 -2, label %next
+ i32 2, label %out
+ i32 3, label %out
+; CHECK-NEXT: !prof ![[MD0:[0-9]+]]
+ ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6}
+
+out:
+ %p = phi i32 [ 1, %entry ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ]
+ ret i32 %p
+
+next:
+ %q = phi i32 [ 0, %negative ], [ 0, %negative ]
+ ret i32 %q
+}
+
+; Removed all cases from switch.
+define i32 @switch2(i32 %s) {
+; CHECK-LABEL: @switch2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[S:%.*]], 0
+; CHECK-NEXT: br i1 [[CMP]], label [[POSITIVE:%.*]], label [[OUT:%.*]]
+;
+entry:
+ %cmp = icmp sgt i32 %s, 0
+ br i1 %cmp, label %positive, label %out
+
+positive:
+ switch i32 %s, label %out [
+ i32 0, label %out
+ i32 -1, label %next
+ i32 -2, label %next
+ ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3}
+
+out:
+ %p = phi i32 [ -1, %entry ], [ 1, %positive ], [ 1, %positive ]
+ ret i32 %p
+
+next:
+ %q = phi i32 [ 0, %positive ], [ 0, %positive ]
+ ret i32 %q
+}
+
+; Change switch into conditional branch.
+define i32 @switch3(i32 %s) {
+; CHECK-LABEL: @switch3(
+;
+entry:
+ %cmp = icmp sgt i32 %s, 0
+ br i1 %cmp, label %positive, label %out
+
+positive:
+; CHECK: positive:
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %s, 1
+; CHECK-NEXT: br i1 [[CMP]], label [[NEXT:%.*]], label [[OUT:%.*]], !prof ![[MD1:[0-9]+]]
+ switch i32 %s, label %out [
+ i32 1, label %next
+ i32 -1, label %next
+ i32 -2, label %next
+ ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3}
+
+out:
+ %p = phi i32 [ -1, %entry ], [ 1, %positive ]
+ ret i32 %p
+
+next:
+ %q = phi i32 [ 0, %positive ], [ 0, %positive ], [ 0, %positive ]
+ ret i32 %q
+}
+
+; Removed all cases from switch.
+define i32 @switch4(i32 %s) {
+; CHECK-LABEL: @switch4(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[S:%.*]], 0
+; CHECK-NEXT: br i1 [[CMP]], label [[NEGATIVE:%.*]], label [[OUT:%.*]]
+;
+entry:
+ %cmp = icmp slt i32 %s, 0
+ br i1 %cmp, label %negative, label %out
+
+negative:
+; CHECK: negative:
+; CHECK-NEXT: br label %out
+ switch i32 %s, label %out [
+ i32 0, label %out
+ i32 1, label %out
+ i32 2, label %out
+ i32 3, label %out
+ ], !prof !{!"branch_weights", i32 99, i32 1, i32 2, i32 3, i32 4}
+
+out:
+ %p = phi i32 [ 1, %entry ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ], [ -1, %negative ]
+ ret i32 %p
+}
+
+; CHECK: ![[MD0]] = !{!"branch_weights", i32 99, i32 4, i32 3}
+; CHECK: ![[MD1]] = !{!"branch_weights", i32 1, i32 99}
OpenPOWER on IntegriCloud