Index: test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll =================================================================== --- test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll +++ test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -simplifycfg -switch-to-lookup -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s ; RUN: opt < %s -passes='simplify-cfg' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s @@ -8,12 +9,32 @@ ; CHECK-NOT: @switch.table.foo = private unnamed_addr constant [4 x i32] [i32 55, i32 123, i32 0, i32 -1] define i32 @foo(i32 %c) "no-jump-tables"="true" { +; CHECK-LABEL: @foo( +; CHECK-NEXT: entry: +; CHECK-NEXT: switch i32 [[C:%.*]], label [[SW_DEFAULT:%.*]] [ +; CHECK-NEXT: i32 42, label [[RETURN:%.*]] +; CHECK-NEXT: i32 43, label [[SW_BB1:%.*]] +; CHECK-NEXT: i32 44, label [[SW_BB2:%.*]] +; CHECK-NEXT: i32 45, label [[SW_BB3:%.*]] +; CHECK-NEXT: ] +; CHECK: sw.bb1: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: sw.bb2: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: sw.bb3: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: sw.default: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: return: +; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 15, [[SW_DEFAULT]] ], [ -1, [[SW_BB3]] ], [ 0, [[SW_BB2]] ], [ 123, [[SW_BB1]] ], [ 55, [[ENTRY:%.*]] ] +; CHECK-NEXT: ret i32 [[RETVAL_0]] +; entry: switch i32 %c, label %sw.default [ - i32 42, label %return - i32 43, label %sw.bb1 - i32 44, label %sw.bb2 - i32 45, label %sw.bb3 + i32 42, label %return + i32 43, label %sw.bb1 + i32 44, label %sw.bb2 + i32 45, label %sw.bb3 ] sw.bb1: br label %return @@ -27,12 +48,24 @@ define i32 @bar(i32 %c) { +; CHECK-LABEL: @bar( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i32 [[C:%.*]], 42 +; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[SWITCH_TABLEIDX]], 4 +; CHECK-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]] +; CHECK: switch.lookup: +; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.bar, i32 0, i32 [[SWITCH_TABLEIDX]] +; CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i32, i32* [[SWITCH_GEP]] +; CHECK-NEXT: ret i32 [[SWITCH_LOAD]] +; CHECK: return: +; CHECK-NEXT: ret i32 15 +; entry: switch i32 %c, label %sw.default [ - i32 42, label %return - i32 43, label %sw.bb1 - i32 44, label %sw.bb2 - i32 45, label %sw.bb3 + i32 42, label %return + i32 43, label %sw.bb1 + i32 44, label %sw.bb2 + i32 45, label %sw.bb3 ] sw.bb1: br label %return Index: test/Transforms/SimplifyCFG/X86/lit.local.cfg =================================================================== --- test/Transforms/SimplifyCFG/X86/lit.local.cfg +++ test/Transforms/SimplifyCFG/X86/lit.local.cfg @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py if not 'X86' in config.root.targets: config.unsupported = True Index: test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll =================================================================== --- test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll +++ test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll @@ -1,14 +1,31 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -simplifycfg -mtriple=x86_64-unknown-unknown -mattr=+bmi < %s | FileCheck %s --check-prefix=ALL --check-prefix=BMI ; RUN: opt -S -simplifycfg -mtriple=x86_64-unknown-unknown -mattr=+lzcnt < %s | FileCheck %s --check-prefix=ALL --check-prefix=LZCNT ; RUN: opt -S -simplifycfg -mtriple=x86_64-unknown-unknown < %s | FileCheck %s --check-prefix=ALL --check-prefix=GENERIC define i64 @test1(i64 %A) { -; ALL-LABEL: @test1( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i64 %A, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true) -; ALL-NEXT: select i1 [[COND]], i64 64, i64 [[CTLZ]] -; ALL: ret +; BMI-LABEL: @test1( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[A]], i1 true) +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]] +; BMI-NEXT: ret i64 [[COND]] +; +; LZCNT-LABEL: @test1( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[A]], i1 true) +; LZCNT-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]] +; LZCNT-NEXT: ret i64 [[SPEC_SELECT]] +; +; GENERIC-LABEL: @test1( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0 +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[A]], i1 true) +; GENERIC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]] +; GENERIC-NEXT: ret i64 [[COND]] +; entry: %tobool = icmp eq i64 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -23,11 +40,27 @@ } define i32 @test2(i32 %A) { -; ALL-LABEL: @test2( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true) -; ALL-NEXT: select i1 [[COND]], i32 32, i32 [[CTLZ]] -; ALL: ret +; BMI-LABEL: @test2( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[A]], i1 true) +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; BMI-NEXT: ret i32 [[COND]] +; +; LZCNT-LABEL: @test2( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[A]], i1 true) +; LZCNT-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; LZCNT-NEXT: ret i32 [[SPEC_SELECT]] +; +; GENERIC-LABEL: @test2( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[A]], i1 true) +; GENERIC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; GENERIC-NEXT: ret i32 [[COND]] +; entry: %tobool = icmp eq i32 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -43,11 +76,27 @@ define signext i16 @test3(i16 signext %A) { -; ALL-LABEL: @test3( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i16 %A, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true) -; ALL-NEXT: select i1 [[COND]], i16 16, i16 [[CTLZ]] -; ALL: ret +; BMI-LABEL: @test3( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.ctlz.i16(i16 [[A]], i1 true) +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]] +; BMI-NEXT: ret i16 [[COND]] +; +; LZCNT-LABEL: @test3( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.ctlz.i16(i16 [[A]], i1 true) +; LZCNT-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]] +; LZCNT-NEXT: ret i16 [[SPEC_SELECT]] +; +; GENERIC-LABEL: @test3( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.ctlz.i16(i16 [[A]], i1 true) +; GENERIC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]] +; GENERIC-NEXT: ret i16 [[COND]] +; entry: %tobool = icmp eq i16 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -63,11 +112,27 @@ define i64 @test1b(i64 %A) { -; ALL-LABEL: @test1b( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i64 %A, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %A, i1 true) -; ALL-NEXT: select i1 [[COND]], i64 64, i64 [[CTTZ]] -; ALL: ret +; BMI-LABEL: @test1b( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 true) +; BMI-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]] +; BMI-NEXT: ret i64 [[SPEC_SELECT]] +; +; LZCNT-LABEL: @test1b( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 true) +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]] +; LZCNT-NEXT: ret i64 [[COND]] +; +; GENERIC-LABEL: @test1b( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0 +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 true) +; GENERIC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]] +; GENERIC-NEXT: ret i64 [[COND]] +; entry: %tobool = icmp eq i64 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -83,11 +148,27 @@ define i32 @test2b(i32 %A) { -; ALL-LABEL: @test2b( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %A, i1 true) -; ALL-NEXT: select i1 [[COND]], i32 32, i32 [[CTTZ]] -; ALL: ret +; BMI-LABEL: @test2b( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[A]], i1 true) +; BMI-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; BMI-NEXT: ret i32 [[SPEC_SELECT]] +; +; LZCNT-LABEL: @test2b( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[A]], i1 true) +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; LZCNT-NEXT: ret i32 [[COND]] +; +; GENERIC-LABEL: @test2b( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[A]], i1 true) +; GENERIC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; GENERIC-NEXT: ret i32 [[COND]] +; entry: %tobool = icmp eq i32 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -103,11 +184,27 @@ define signext i16 @test3b(i16 signext %A) { -; ALL-LABEL: @test3b( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i16 %A, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i16 @llvm.cttz.i16(i16 %A, i1 true) -; ALL-NEXT: select i1 [[COND]], i16 16, i16 [[CTTZ]] -; ALL: ret +; BMI-LABEL: @test3b( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.cttz.i16(i16 [[A]], i1 true) +; BMI-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]] +; BMI-NEXT: ret i16 [[SPEC_SELECT]] +; +; LZCNT-LABEL: @test3b( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.cttz.i16(i16 [[A]], i1 true) +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]] +; LZCNT-NEXT: ret i16 [[COND]] +; +; GENERIC-LABEL: @test3b( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.cttz.i16(i16 [[A]], i1 true) +; GENERIC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]] +; GENERIC-NEXT: ret i16 [[COND]] +; entry: %tobool = icmp eq i16 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -126,14 +223,38 @@ ; for the target. define i64 @test1e(i32 %x) { -; ALL-LABEL: @test1e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i32 %x, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %x, i1 true) -; ALL: [[ZEXT:%[A-Za-z0-9]+]] = zext i32 [[CTTZ]] to i64 -; BMI-NEXT: select i1 [[COND]], i64 32, i64 [[ZEXT]] -; LZCNT-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test1e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true) +; BMI-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64 +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 32, i64 [[PHITMP2]] +; BMI-NEXT: ret i64 [[COND]] +; +; LZCNT-LABEL: @test1e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; LZCNT-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; LZCNT: cond.true: +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true) +; LZCNT-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64 +; LZCNT-NEXT: br label [[COND_END]] +; LZCNT: cond.end: +; LZCNT-NEXT: [[COND:%.*]] = phi i64 [ [[PHITMP2]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; LZCNT-NEXT: ret i64 [[COND]] +; +; GENERIC-LABEL: @test1e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true) +; GENERIC-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i64 [ [[PHITMP2]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i64 [[COND]] +; entry: %tobool = icmp eq i32 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -149,14 +270,38 @@ } define i32 @test2e(i64 %x) { -; ALL-LABEL: @test2e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i64 %x, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %x, i1 true) -; ALL: [[TRUNC:%[A-Za-z0-9]+]] = trunc i64 [[CTTZ]] to i32 -; BMI-NEXT: select i1 [[COND]], i32 64, i32 [[TRUNC]] -; LZCNT-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test2e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true) +; BMI-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32 +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 64, i32 [[CAST]] +; BMI-NEXT: ret i32 [[COND]] +; +; LZCNT-LABEL: @test2e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; LZCNT-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; LZCNT: cond.true: +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true) +; LZCNT-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32 +; LZCNT-NEXT: br label [[COND_END]] +; LZCNT: cond.end: +; LZCNT-NEXT: [[COND:%.*]] = phi i32 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; LZCNT-NEXT: ret i32 [[COND]] +; +; GENERIC-LABEL: @test2e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true) +; GENERIC-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i32 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i32 [[COND]] +; entry: %tobool = icmp eq i64 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -172,14 +317,38 @@ } define i64 @test3e(i32 %x) { -; ALL-LABEL: @test3e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i32 %x, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) -; ALL: [[ZEXT:%[A-Za-z0-9]+]] = zext i32 [[CTLZ]] to i64 -; LZCNT-NEXT: select i1 [[COND]], i64 32, i64 [[ZEXT]] -; BMI-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test3e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; BMI-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; BMI: cond.true: +; BMI-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true) +; BMI-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64 +; BMI-NEXT: br label [[COND_END]] +; BMI: cond.end: +; BMI-NEXT: [[COND:%.*]] = phi i64 [ [[PHITMP2]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; BMI-NEXT: ret i64 [[COND]] +; +; LZCNT-LABEL: @test3e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true) +; LZCNT-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64 +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 32, i64 [[PHITMP2]] +; LZCNT-NEXT: ret i64 [[COND]] +; +; GENERIC-LABEL: @test3e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true) +; GENERIC-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i64 [ [[PHITMP2]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i64 [[COND]] +; entry: %tobool = icmp eq i32 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -195,14 +364,38 @@ } define i32 @test4e(i64 %x) { -; ALL-LABEL: @test4e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i64 %x, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %x, i1 true) -; ALL: [[TRUNC:%[A-Za-z0-9]+]] = trunc i64 [[CTLZ]] to i32 -; LZCNT-NEXT: select i1 [[COND]], i32 64, i32 [[TRUNC]] -; BMI-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test4e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; BMI-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; BMI: cond.true: +; BMI-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true) +; BMI-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32 +; BMI-NEXT: br label [[COND_END]] +; BMI: cond.end: +; BMI-NEXT: [[COND:%.*]] = phi i32 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; BMI-NEXT: ret i32 [[COND]] +; +; LZCNT-LABEL: @test4e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true) +; LZCNT-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32 +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 64, i32 [[CAST]] +; LZCNT-NEXT: ret i32 [[COND]] +; +; GENERIC-LABEL: @test4e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true) +; GENERIC-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i32 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i32 [[COND]] +; entry: %tobool = icmp eq i64 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -218,14 +411,38 @@ } define i16 @test5e(i64 %x) { -; ALL-LABEL: @test5e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i64 %x, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %x, i1 true) -; ALL: [[TRUNC:%[A-Za-z0-9]+]] = trunc i64 [[CTLZ]] to i16 -; LZCNT-NEXT: select i1 [[COND]], i16 64, i16 [[TRUNC]] -; BMI-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test5e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; BMI-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; BMI: cond.true: +; BMI-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true) +; BMI-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16 +; BMI-NEXT: br label [[COND_END]] +; BMI: cond.end: +; BMI-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; BMI-NEXT: ret i16 [[COND]] +; +; LZCNT-LABEL: @test5e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true) +; LZCNT-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16 +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 64, i16 [[CAST]] +; LZCNT-NEXT: ret i16 [[COND]] +; +; GENERIC-LABEL: @test5e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true) +; GENERIC-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i16 [[COND]] +; entry: %tobool = icmp eq i64 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -241,14 +458,38 @@ } define i16 @test6e(i32 %x) { -; ALL-LABEL: @test6e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i32 %x, 0 -; ALL: [[CTLZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) -; ALL: [[TRUNC:%[A-Za-z0-9]+]] = trunc i32 [[CTLZ]] to i16 -; LZCNT-NEXT: select i1 [[COND]], i16 32, i16 [[TRUNC]] -; BMI-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test6e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; BMI-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; BMI: cond.true: +; BMI-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true) +; BMI-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16 +; BMI-NEXT: br label [[COND_END]] +; BMI: cond.end: +; BMI-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; BMI-NEXT: ret i16 [[COND]] +; +; LZCNT-LABEL: @test6e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true) +; LZCNT-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16 +; LZCNT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 32, i16 [[CAST]] +; LZCNT-NEXT: ret i16 [[COND]] +; +; GENERIC-LABEL: @test6e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true) +; GENERIC-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i16 [[COND]] +; entry: %tobool = icmp eq i32 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -264,14 +505,38 @@ } define i16 @test7e(i64 %x) { -; ALL-LABEL: @test7e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i64 %x, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %x, i1 true) -; ALL: [[TRUNC:%[A-Za-z0-9]+]] = trunc i64 [[CTTZ]] to i16 -; BMI-NEXT: select i1 [[COND]], i16 64, i16 [[TRUNC]] -; LZCNT-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test7e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true) +; BMI-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16 +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 64, i16 [[CAST]] +; BMI-NEXT: ret i16 [[COND]] +; +; LZCNT-LABEL: @test7e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; LZCNT-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; LZCNT: cond.true: +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true) +; LZCNT-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16 +; LZCNT-NEXT: br label [[COND_END]] +; LZCNT: cond.end: +; LZCNT-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; LZCNT-NEXT: ret i16 [[COND]] +; +; GENERIC-LABEL: @test7e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true) +; GENERIC-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 64, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i16 [[COND]] +; entry: %tobool = icmp eq i64 %x, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -287,14 +552,38 @@ } define i16 @test8e(i32 %x) { -; ALL-LABEL: @test8e( -; ALL: [[COND:%[A-Za-z0-9]+]] = icmp eq i32 %x, 0 -; ALL: [[CTTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %x, i1 true) -; ALL: [[TRUNC:%[A-Za-z0-9]+]] = trunc i32 [[CTTZ]] to i16 -; BMI-NEXT: select i1 [[COND]], i16 32, i16 [[TRUNC]] -; LZCNT-NOT: select -; GENERIC-NOT: select -; ALL: ret +; BMI-LABEL: @test8e( +; BMI-NEXT: entry: +; BMI-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; BMI-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true) +; BMI-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16 +; BMI-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 32, i16 [[CAST]] +; BMI-NEXT: ret i16 [[COND]] +; +; LZCNT-LABEL: @test8e( +; LZCNT-NEXT: entry: +; LZCNT-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; LZCNT-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; LZCNT: cond.true: +; LZCNT-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true) +; LZCNT-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16 +; LZCNT-NEXT: br label [[COND_END]] +; LZCNT: cond.end: +; LZCNT-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; LZCNT-NEXT: ret i16 [[COND]] +; +; GENERIC-LABEL: @test8e( +; GENERIC-NEXT: entry: +; GENERIC-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0 +; GENERIC-NEXT: br i1 [[TOBOOL]], label [[COND_END:%.*]], label [[COND_TRUE:%.*]] +; GENERIC: cond.true: +; GENERIC-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true) +; GENERIC-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16 +; GENERIC-NEXT: br label [[COND_END]] +; GENERIC: cond.end: +; GENERIC-NEXT: [[COND:%.*]] = phi i16 [ [[CAST]], [[COND_TRUE]] ], [ 32, [[ENTRY:%.*]] ] +; GENERIC-NEXT: ret i16 [[COND]] +; entry: %tobool = icmp eq i32 %x, 0 br i1 %tobool, label %cond.end, label %cond.true Index: test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll =================================================================== --- test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll +++ test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -simplifycfg -switch-to-lookup < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s ; RUN: opt -S -passes='simplify-cfg' < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s @@ -16,14 +17,23 @@ ; CHECK-NEXT: add i64 ; CHECK-NEXT: ret i64 define i64 @test(i3 %arg) { +; CHECK-LABEL: @test( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i3 [[ARG:%.*]], -4 +; CHECK-NEXT: [[SWITCH_TABLEIDX_ZEXT:%.*]] = zext i3 [[SWITCH_TABLEIDX]] to i4 +; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [8 x i64], [8 x i64]* @switch.table.test, i32 0, i4 [[SWITCH_TABLEIDX_ZEXT]] +; CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i64, i64* [[SWITCH_GEP]] +; CHECK-NEXT: [[V3:%.*]] = add i64 [[SWITCH_LOAD]], 0 +; CHECK-NEXT: ret i64 [[V3]] +; entry: switch i3 %arg, label %Default [ - i3 -2, label %Label6 - i3 1, label %Label1 - i3 2, label %Label2 - i3 3, label %Label3 - i3 -4, label %Label4 - i3 -3, label %Label5 + i3 -2, label %Label6 + i3 1, label %Label1 + i3 2, label %Label2 + i3 3, label %Label3 + i3 -4, label %Label4 + i3 -3, label %Label5 ] Default: Index: test/Transforms/SimplifyCFG/X86/switch-table-bug.ll =================================================================== --- test/Transforms/SimplifyCFG/X86/switch-table-bug.ll +++ test/Transforms/SimplifyCFG/X86/switch-table-bug.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -simplifycfg -switch-to-lookup < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s ; RUN: opt -S -passes='simplify-cfg' < %s -mtriple=x86_64-apple-darwin12.0.0 | FileCheck %s @@ -14,12 +15,20 @@ ; CHECK-NEXT: load i64, i64* %switch.gep ; CHECK-NEXT: ret i64 %switch.load define i64 @_TFO6reduce1E5toRawfS0_FT_Si(i2) { +; CHECK-LABEL: @_TFO6reduce1E5toRawfS0_FT_Si( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i2 [[TMP0:%.*]], -2 +; CHECK-NEXT: [[SWITCH_TABLEIDX_ZEXT:%.*]] = zext i2 [[SWITCH_TABLEIDX]] to i3 +; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [4 x i64], [4 x i64]* @switch.table._TFO6reduce1E5toRawfS0_FT_Si, i32 0, i3 [[SWITCH_TABLEIDX_ZEXT]] +; CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i64, i64* [[SWITCH_GEP]] +; CHECK-NEXT: ret i64 [[SWITCH_LOAD]] +; entry: switch i2 %0, label %1 [ - i2 0, label %2 - i2 1, label %3 - i2 -2, label %4 - i2 -1, label %5 + i2 0, label %2 + i2 1, label %3 + i2 -2, label %4 + i2 -1, label %5 ] ;