134 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S -passes=jump-threading < %s | FileCheck %s3 4; Check that the heuristic for avoiding accidental introduction of irreducible5; loops doesn't also prevent us from threading simple constructs where this6; isn't a problem.7 8declare void @opaque_body()9 10define void @jump_threading_loopheader() {11; CHECK-LABEL: @jump_threading_loopheader(12; CHECK-NEXT: top:13; CHECK-NEXT: br label [[ENTRY:%.*]]14; CHECK: entry:15; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]16; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 117; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 1018; CHECK-NEXT: br i1 [[CMP]], label [[LATCH]], label [[EXIT:%.*]]19; CHECK: latch:20; CHECK-NEXT: call void @opaque_body()21; CHECK-NEXT: br label [[ENTRY]]22; CHECK: exit:23; CHECK-NEXT: ret void24;25top:26 br label %entry27 28entry:29 %ind = phi i32 [0, %top], [%nextind, %latch]30 %nextind = add i32 %ind, 131 %cmp = icmp ule i32 %ind, 1032 br i1 %cmp, label %body, label %latch33 34body:35 call void @opaque_body()36 br label %latch37 38latch:39 %cond = phi i2 [1, %entry], [2, %body]40 switch i2 %cond, label %unreach [41 i2 2, label %entry42 i2 1, label %exit43 ]44 45unreach:46 unreachable47 48exit:49 ret void50}51 52; We also need to check the opposite order of the branches, in the switch53; instruction because jump-threading relies on that to decide which edge to54; try to thread first.55define void @jump_threading_loopheader2() {56; CHECK-LABEL: @jump_threading_loopheader2(57; CHECK-NEXT: top:58; CHECK-NEXT: br label [[ENTRY:%.*]]59; CHECK: entry:60; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]61; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 162; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 1063; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LATCH]]64; CHECK: latch:65; CHECK-NEXT: br label [[ENTRY]]66; CHECK: exit:67; CHECK-NEXT: call void @opaque_body()68; CHECK-NEXT: ret void69;70top:71 br label %entry72 73entry:74 %ind = phi i32 [0, %top], [%nextind, %latch]75 %nextind = add i32 %ind, 176 %cmp = icmp ule i32 %ind, 1077 br i1 %cmp, label %body, label %latch78 79body:80 call void @opaque_body()81 br label %latch82 83latch:84 %cond = phi i2 [1, %entry], [2, %body]85 switch i2 %cond, label %unreach [86 i2 1, label %entry87 i2 2, label %exit88 ]89 90unreach:91 unreachable92 93exit:94 ret void95}96 97; Check if we can handle undef branch condition.98define void @jump_threading_loopheader3() {99; CHECK-LABEL: @jump_threading_loopheader3(100; CHECK-NEXT: top:101; CHECK-NEXT: br label [[ENTRY:%.*]]102; CHECK: entry:103; CHECK-NEXT: [[IND:%.*]] = phi i32 [ 0, [[TOP:%.*]] ], [ [[NEXTIND:%.*]], [[LATCH:%.*]] ]104; CHECK-NEXT: [[NEXTIND]] = add i32 [[IND]], 1105; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[IND]], 10106; CHECK-NEXT: br i1 [[CMP]], label [[LATCH]], label [[EXIT:%.*]]107; CHECK: latch:108; CHECK-NEXT: call void @opaque_body()109; CHECK-NEXT: br label [[ENTRY]]110; CHECK: exit:111; CHECK-NEXT: ret void112;113top:114 br label %entry115 116entry:117 %ind = phi i32 [0, %top], [%nextind, %latch]118 %nextind = add i32 %ind, 1119 %cmp = icmp ule i32 %ind, 10120 br i1 %cmp, label %body, label %latch121 122body:123 call void @opaque_body()124 br label %latch125 126latch:127 %phi = phi i32 [undef, %entry], [0, %body]128 %cmp1 = icmp eq i32 %phi, 0129 br i1 %cmp1, label %entry, label %exit130 131exit:132 ret void133}134