From: Sanjay Patel Date: Mon, 3 Dec 2018 16:55:29 +0000 (+0000) Subject: [SimplifyCFG] add tests for cross block compare folding; NFC X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8918a511a1a53cc568b248428fb75c39b1949001;p=platform%2Fupstream%2Fllvm.git [SimplifyCFG] add tests for cross block compare folding; NFC These are the baseline tests for D54827. Patch based on code originally written by: @yinyuefengyi (luo xionghu) Differential Revision: https://reviews.llvm.org/D54994 llvm-svn: 348151 --- diff --git a/llvm/test/Transforms/SimplifyCFG/branch-fold-three.ll b/llvm/test/Transforms/SimplifyCFG/branch-fold-three.ll new file mode 100644 index 0000000..953749b --- /dev/null +++ b/llvm/test/Transforms/SimplifyCFG/branch-fold-three.ll @@ -0,0 +1,259 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -simplifycfg -S | FileCheck %s + +; s >= t, s != t, s <= t +define void @foo1(i32 %s, i32 %t) { +; CHECK-LABEL: @foo1( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[S:%.*]], [[T:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]] +; CHECK: if.then: +; CHECK-NEXT: call void @bar1(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]] +; CHECK: if.then2: +; CHECK-NEXT: call void @bar2(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]] +; CHECK: if.then4: +; CHECK-NEXT: call void @bar3(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: br label [[IF_END6]] +; CHECK: if.end6: +; CHECK-NEXT: ret void +; +entry: + %cmp = icmp sge i32 %s, %t + br i1 %cmp, label %if.then, label %if.end6 + +if.then: + call void @bar1(i32 %s, i32 %t) + %cmp1 = icmp ne i32 %s, %t + br i1 %cmp1, label %if.then2, label %if.end6 + +if.then2: + call void @bar2(i32 %s, i32 %t) + %cmp3 = icmp sle i32 %s, %t + br i1 %cmp3, label %if.then4, label %if.end6 + +if.then4: + call void @bar3(i32 %s, i32 %t) + br label %if.end6 + +if.end6: + ret void +} + +; s != t, s >= t, s <= t +define void @foo11(i32 %s, i32 %t) { +; CHECK-LABEL: @foo11( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[S:%.*]], [[T:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]] +; CHECK: if.then: +; CHECK-NEXT: call void @bar1(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP1:%.*]] = icmp sge i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]] +; CHECK: if.then2: +; CHECK-NEXT: call void @bar2(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]] +; CHECK: if.then4: +; CHECK-NEXT: call void @bar3(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: br label [[IF_END6]] +; CHECK: if.end6: +; CHECK-NEXT: ret void +; +entry: + %cmp = icmp ne i32 %s, %t + br i1 %cmp, label %if.then, label %if.end6 + +if.then: + call void @bar1(i32 %s, i32 %t) + %cmp1 = icmp sge i32 %s, %t + br i1 %cmp1, label %if.then2, label %if.end6 + +if.then2: + call void @bar2(i32 %s, i32 %t) + %cmp3 = icmp sle i32 %s, %t + br i1 %cmp3, label %if.then4, label %if.end6 + +if.then4: + call void @bar3(i32 %s, i32 %t) + br label %if.end6 + +if.end6: + ret void +} + +; s >= t, t != s, s <= t +define void @foo2(i32 %s, i32 %t) { +; CHECK-LABEL: @foo2( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[S:%.*]], [[T:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]] +; CHECK: if.then: +; CHECK-NEXT: call void @bar1(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[T]], [[S]] +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]] +; CHECK: if.then2: +; CHECK-NEXT: call void @bar2(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]] +; CHECK: if.then4: +; CHECK-NEXT: call void @bar3(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: br label [[IF_END6]] +; CHECK: if.end6: +; CHECK-NEXT: ret void +; +entry: + %cmp = icmp sge i32 %s, %t + br i1 %cmp, label %if.then, label %if.end6 + +if.then: + call void @bar1(i32 %s, i32 %t) + %cmp1 = icmp ne i32 %t, %s + br i1 %cmp1, label %if.then2, label %if.end6 + +if.then2: + call void @bar2(i32 %s, i32 %t) + %cmp3 = icmp sle i32 %s, %t + br i1 %cmp3, label %if.then4, label %if.end6 + +if.then4: + call void @bar3(i32 %s, i32 %t) + br label %if.end6 + +if.end6: + ret void +} + +; s != t, t <= s, s <= t +define void @foo21(i32 %s, i32 %t) { +; CHECK-LABEL: @foo21( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[S:%.*]], [[T:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]] +; CHECK: if.then: +; CHECK-NEXT: call void @bar1(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP1:%.*]] = icmp sle i32 [[T]], [[S]] +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]] +; CHECK: if.then2: +; CHECK-NEXT: call void @bar2(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]] +; CHECK: if.then4: +; CHECK-NEXT: call void @bar3(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: br label [[IF_END6]] +; CHECK: if.end6: +; CHECK-NEXT: ret void +; +entry: + %cmp = icmp ne i32 %s, %t + br i1 %cmp, label %if.then, label %if.end6 + +if.then: + call void @bar1(i32 %s, i32 %t) + %cmp1 = icmp sle i32 %t, %s + br i1 %cmp1, label %if.then2, label %if.end6 + +if.then2: + call void @bar2(i32 %s, i32 %t) + %cmp3 = icmp sle i32 %s, %t + br i1 %cmp3, label %if.then4, label %if.end6 + +if.then4: + call void @bar3(i32 %s, i32 %t) + br label %if.end6 + +if.end6: + ret void +} + +; t <= s, t != s, s <= t +define void @foo3(i32 %s, i32 %t) { +; CHECK-LABEL: @foo3( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[T:%.*]], [[S:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]] +; CHECK: if.then: +; CHECK-NEXT: call void @bar1(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[T]], [[S]] +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]] +; CHECK: if.then2: +; CHECK-NEXT: call void @bar2(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]] +; CHECK: if.then4: +; CHECK-NEXT: call void @bar3(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: br label [[IF_END6]] +; CHECK: if.end6: +; CHECK-NEXT: ret void +; +entry: + %cmp = icmp sle i32 %t, %s + br i1 %cmp, label %if.then, label %if.end6 + +if.then: + call void @bar1(i32 %s, i32 %t) + %cmp1 = icmp ne i32 %t, %s + br i1 %cmp1, label %if.then2, label %if.end6 + +if.then2: + call void @bar2(i32 %s, i32 %t) + %cmp3 = icmp sle i32 %s, %t + br i1 %cmp3, label %if.then4, label %if.end6 + +if.then4: + call void @bar3(i32 %s, i32 %t) + br label %if.end6 + +if.end6: + ret void +} + +; t != s, t <= s, s <= t +define void @foo31(i32 %s, i32 %t) { +; CHECK-LABEL: @foo31( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[T:%.*]], [[S:%.*]] +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]] +; CHECK: if.then: +; CHECK-NEXT: call void @bar1(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP1:%.*]] = icmp sle i32 [[T]], [[S]] +; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]] +; CHECK: if.then2: +; CHECK-NEXT: call void @bar2(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]] +; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]] +; CHECK: if.then4: +; CHECK-NEXT: call void @bar3(i32 [[S]], i32 [[T]]) +; CHECK-NEXT: br label [[IF_END6]] +; CHECK: if.end6: +; CHECK-NEXT: ret void +; +entry: + %cmp = icmp ne i32 %t, %s + br i1 %cmp, label %if.then, label %if.end6 + +if.then: + call void @bar1(i32 %s, i32 %t) + %cmp1 = icmp sle i32 %t, %s + br i1 %cmp1, label %if.then2, label %if.end6 + +if.then2: + call void @bar2(i32 %s, i32 %t) + %cmp3 = icmp sle i32 %s, %t + br i1 %cmp3, label %if.then4, label %if.end6 + +if.then4: + call void @bar3(i32 %s, i32 %t) + br label %if.end6 + +if.end6: + ret void +} + +declare void @bar1(i32, i32) +declare void @bar2(i32, i32) +declare void @bar3(i32, i32) +