From: Shawn Landden Date: Sun, 26 May 2019 13:52:41 +0000 (+0000) Subject: [SimplifyCFG] NFC, update Switch tests to HEAD so I can see if my changes change... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50c73a044f22e97ea384c461bcdd2ea4fbed0156;p=platform%2Fupstream%2Fllvm.git [SimplifyCFG] NFC, update Switch tests to HEAD so I can see if my changes change anything Also add baseline tests to show effect of later patches. llvm-svn: 361725 --- diff --git a/llvm/test/Transforms/SimplifyCFG/ARM/cttz-ctlz.ll b/llvm/test/Transforms/SimplifyCFG/ARM/cttz-ctlz.ll index ffcf217..22f5e9f 100644 --- a/llvm/test/Transforms/SimplifyCFG/ARM/cttz-ctlz.ll +++ b/llvm/test/Transforms/SimplifyCFG/ARM/cttz-ctlz.ll @@ -1,11 +1,14 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -simplifycfg -mtriple=arm -mattr=+v6t2 < %s | FileCheck %s define i32 @ctlz(i32 %A) { ; CHECK-LABEL: @ctlz( -; CHECK: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0 -; CHECK-NEXT: [[CTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true) -; CHECK-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i32 32, i32 [[CTZ]] -; CHECK-NEXT: ret i32 [[SEL]] +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[A]], i1 true) +; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; CHECK-NEXT: ret i32 [[SPEC_SELECT]] +; entry: %tobool = icmp eq i32 %A, 0 br i1 %tobool, label %cond.end, label %cond.true @@ -21,10 +24,12 @@ cond.end: define i32 @cttz(i32 %A) { ; CHECK-LABEL: @cttz( -; CHECK: [[ICMP:%[A-Za-z0-9]+]] = icmp eq i32 %A, 0 -; CHECK-NEXT: [[CTZ:%[A-Za-z0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %A, i1 true) -; CHECK-NEXT: [[SEL:%[A-Za-z0-9.]+]] = select i1 [[ICMP]], i32 32, i32 [[CTZ]] -; CHECK-NEXT: ret i32 [[SEL]] +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[A]], i1 true) +; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]] +; CHECK-NEXT: ret i32 [[SPEC_SELECT]] +; entry: %tobool = icmp eq i32 %A, 0 br i1 %tobool, label %cond.end, label %cond.true diff --git a/llvm/test/Transforms/SimplifyCFG/ARM/select-trunc-i64.ll b/llvm/test/Transforms/SimplifyCFG/ARM/select-trunc-i64.ll index 9484de7..9218ee1 100644 --- a/llvm/test/Transforms/SimplifyCFG/ARM/select-trunc-i64.ll +++ b/llvm/test/Transforms/SimplifyCFG/ARM/select-trunc-i64.ll @@ -1,11 +1,20 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ;RUN: opt -S -simplifycfg -mtriple=arm < %s | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" -; CHECK-LABEL: select_trunc_i64 -; CHECK-NOT: br -; CHECK: select -; CHECK: select define arm_aapcscc i32 @select_trunc_i64(i32 %a, i32 %b) { +; CHECK-LABEL: @select_trunc_i64( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[A:%.*]] to i64 +; CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[B:%.*]] to i64 +; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[CONV1]], [[CONV]] +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[ADD]], 2147483647 +; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i64 [[ADD]], -2147483648 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TMP0]], i64 [[ADD]], i64 -2147483648 +; CHECK-NEXT: [[EXTRACT_T:%.*]] = trunc i64 [[COND]] to i32 +; CHECK-NEXT: [[COND8_OFF0:%.*]] = select i1 [[CMP]], i32 2147483647, i32 [[EXTRACT_T]] +; CHECK-NEXT: ret i32 [[COND8_OFF0]] +; entry: %conv = sext i32 %a to i64 %conv1 = sext i32 %b to i64 diff --git a/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll b/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll index 453a768..f677371 100644 --- a/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll +++ b/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table-constant-expr.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -simplifycfg < %s | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" @@ -15,11 +16,28 @@ target triple = "armv7a--none-eabi" @g4 = external thread_local global i32, align 4 define i32* @test3(i32 %n) { +; CHECK-LABEL: @test3( +; CHECK-NEXT: entry: +; CHECK-NEXT: switch i32 [[N:%.*]], label [[SW_DEFAULT:%.*]] [ +; CHECK-NEXT: i32 0, label [[RETURN:%.*]] +; CHECK-NEXT: i32 1, label [[SW_BB1:%.*]] +; CHECK-NEXT: i32 2, label [[SW_BB2:%.*]] +; CHECK-NEXT: ] +; CHECK: sw.bb1: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: sw.bb2: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: sw.default: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: return: +; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32* [ @g4, [[SW_DEFAULT]] ], [ getelementptr inbounds (i32, i32* inttoptr (i32 mul (i32 ptrtoint (i32* @g3 to i32), i32 2) to i32*), i32 1), [[SW_BB2]] ], [ @g2, [[SW_BB1]] ], [ @g1, [[ENTRY:%.*]] ] +; CHECK-NEXT: ret i32* [[RETVAL_0]] +; entry: switch i32 %n, label %sw.default [ - i32 0, label %sw.bb - i32 1, label %sw.bb1 - i32 2, label %sw.bb2 + i32 0, label %sw.bb + i32 1, label %sw.bb1 + i32 2, label %sw.bb2 ] sw.bb: diff --git a/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll b/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll index 501bc31..a931e90 100644 --- a/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-lookup-table.ll +++ b/llvm/test/Transforms/SimplifyCFG/ARM/switch-to-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 -mtriple=arm -relocation-model=static < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=pic < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE ; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=ropi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE @@ -22,11 +23,22 @@ target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" target triple = "armv7a--none-eabi" define i32 @test1(i32 %n) { +; CHECK-LABEL: @test1( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[N:%.*]], 3 +; CHECK-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]] +; CHECK: switch.lookup: +; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.test1, i32 0, i32 [[N]] +; CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i32, i32* [[SWITCH_GEP]] +; CHECK-NEXT: ret i32 [[SWITCH_LOAD]] +; CHECK: return: +; CHECK-NEXT: ret i32 15498 +; entry: switch i32 %n, label %sw.default [ - i32 0, label %sw.bb - i32 1, label %sw.bb1 - i32 2, label %sw.bb2 + i32 0, label %sw.bb + i32 1, label %sw.bb1 + i32 2, label %sw.bb2 ] sw.bb: @@ -53,11 +65,39 @@ return: define i32* @test2(i32 %n) { +; ENABLE-LABEL: @test2( +; ENABLE-NEXT: entry: +; ENABLE-NEXT: [[TMP0:%.*]] = icmp ult i32 [[N:%.*]], 3 +; ENABLE-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]] +; ENABLE: switch.lookup: +; ENABLE-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.test2, i32 0, i32 [[N]] +; ENABLE-NEXT: [[SWITCH_LOAD:%.*]] = load i32*, i32** [[SWITCH_GEP]] +; ENABLE-NEXT: ret i32* [[SWITCH_LOAD]] +; ENABLE: return: +; ENABLE-NEXT: ret i32* @c4 +; +; DISABLE-LABEL: @test2( +; DISABLE-NEXT: entry: +; DISABLE-NEXT: switch i32 [[N:%.*]], label [[SW_DEFAULT:%.*]] [ +; DISABLE-NEXT: i32 0, label [[RETURN:%.*]] +; DISABLE-NEXT: i32 1, label [[SW_BB1:%.*]] +; DISABLE-NEXT: i32 2, label [[SW_BB2:%.*]] +; DISABLE-NEXT: ] +; DISABLE: sw.bb1: +; DISABLE-NEXT: br label [[RETURN]] +; DISABLE: sw.bb2: +; DISABLE-NEXT: br label [[RETURN]] +; DISABLE: sw.default: +; DISABLE-NEXT: br label [[RETURN]] +; DISABLE: return: +; DISABLE-NEXT: [[RETVAL_0:%.*]] = phi i32* [ @c4, [[SW_DEFAULT]] ], [ @c3, [[SW_BB2]] ], [ @c2, [[SW_BB1]] ], [ @c1, [[ENTRY:%.*]] ] +; DISABLE-NEXT: ret i32* [[RETVAL_0]] +; entry: switch i32 %n, label %sw.default [ - i32 0, label %sw.bb - i32 1, label %sw.bb1 - i32 2, label %sw.bb2 + i32 0, label %sw.bb + i32 1, label %sw.bb1 + i32 2, label %sw.bb2 ] sw.bb: @@ -83,11 +123,39 @@ return: @g4 = external global i32, align 4 define i32* @test3(i32 %n) { +; ENABLE-LABEL: @test3( +; ENABLE-NEXT: entry: +; ENABLE-NEXT: [[TMP0:%.*]] = icmp ult i32 [[N:%.*]], 3 +; ENABLE-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]] +; ENABLE: switch.lookup: +; ENABLE-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x i32*], [3 x i32*]* @switch.table.test3, i32 0, i32 [[N]] +; ENABLE-NEXT: [[SWITCH_LOAD:%.*]] = load i32*, i32** [[SWITCH_GEP]] +; ENABLE-NEXT: ret i32* [[SWITCH_LOAD]] +; ENABLE: return: +; ENABLE-NEXT: ret i32* @g4 +; +; DISABLE-LABEL: @test3( +; DISABLE-NEXT: entry: +; DISABLE-NEXT: switch i32 [[N:%.*]], label [[SW_DEFAULT:%.*]] [ +; DISABLE-NEXT: i32 0, label [[RETURN:%.*]] +; DISABLE-NEXT: i32 1, label [[SW_BB1:%.*]] +; DISABLE-NEXT: i32 2, label [[SW_BB2:%.*]] +; DISABLE-NEXT: ] +; DISABLE: sw.bb1: +; DISABLE-NEXT: br label [[RETURN]] +; DISABLE: sw.bb2: +; DISABLE-NEXT: br label [[RETURN]] +; DISABLE: sw.default: +; DISABLE-NEXT: br label [[RETURN]] +; DISABLE: return: +; DISABLE-NEXT: [[RETVAL_0:%.*]] = phi i32* [ @g4, [[SW_DEFAULT]] ], [ @g3, [[SW_BB2]] ], [ @g2, [[SW_BB1]] ], [ @g1, [[ENTRY:%.*]] ] +; DISABLE-NEXT: ret i32* [[RETVAL_0]] +; entry: switch i32 %n, label %sw.default [ - i32 0, label %sw.bb - i32 1, label %sw.bb1 - i32 2, label %sw.bb2 + i32 0, label %sw.bb + i32 1, label %sw.bb1 + i32 2, label %sw.bb2 ] sw.bb: @@ -114,6 +182,44 @@ declare i32 @f4(i32, i32) declare i32 @f5(i32, i32) define i32 @test4(i32 %a, i32 %b, i32 %c) { +; ENABLE-LABEL: @test4( +; ENABLE-NEXT: entry: +; ENABLE-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i32 [[A:%.*]], 1 +; ENABLE-NEXT: [[TMP0:%.*]] = icmp ult i32 [[SWITCH_TABLEIDX]], 3 +; ENABLE-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[COND_FALSE6:%.*]] +; ENABLE: cond.false6: +; ENABLE-NEXT: [[CMP7:%.*]] = icmp eq i32 [[A]], 4 +; ENABLE-NEXT: [[COND:%.*]] = select i1 [[CMP7]], i32 (i32, i32)* @f4, i32 (i32, i32)* @f5 +; ENABLE-NEXT: br label [[COND_END11:%.*]] +; ENABLE: switch.lookup: +; ENABLE-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x i32 (i32, i32)*], [3 x i32 (i32, i32)*]* @switch.table.test4, i32 0, i32 [[SWITCH_TABLEIDX]] +; ENABLE-NEXT: [[SWITCH_LOAD:%.*]] = load i32 (i32, i32)*, i32 (i32, i32)** [[SWITCH_GEP]] +; ENABLE-NEXT: br label [[COND_END11]] +; ENABLE: cond.end11: +; ENABLE-NEXT: [[COND12:%.*]] = phi i32 (i32, i32)* [ [[COND]], [[COND_FALSE6]] ], [ [[SWITCH_LOAD]], [[SWITCH_LOOKUP]] ] +; ENABLE-NEXT: [[CALL:%.*]] = call i32 [[COND12]](i32 [[B:%.*]], i32 [[C:%.*]]) +; ENABLE-NEXT: ret i32 [[CALL]] +; +; DISABLE-LABEL: @test4( +; DISABLE-NEXT: entry: +; DISABLE-NEXT: switch i32 [[A:%.*]], label [[COND_FALSE6:%.*]] [ +; DISABLE-NEXT: i32 1, label [[COND_END11:%.*]] +; DISABLE-NEXT: i32 2, label [[COND_END11_FOLD_SPLIT:%.*]] +; DISABLE-NEXT: i32 3, label [[COND_END11_FOLD_SPLIT1:%.*]] +; DISABLE-NEXT: ] +; DISABLE: cond.false6: +; DISABLE-NEXT: [[CMP7:%.*]] = icmp eq i32 [[A]], 4 +; DISABLE-NEXT: [[COND:%.*]] = select i1 [[CMP7]], i32 (i32, i32)* @f4, i32 (i32, i32)* @f5 +; DISABLE-NEXT: br label [[COND_END11]] +; DISABLE: cond.end11.fold.split: +; DISABLE-NEXT: br label [[COND_END11]] +; DISABLE: cond.end11.fold.split1: +; DISABLE-NEXT: br label [[COND_END11]] +; DISABLE: cond.end11: +; DISABLE-NEXT: [[COND12:%.*]] = phi i32 (i32, i32)* [ @f1, [[ENTRY:%.*]] ], [ [[COND]], [[COND_FALSE6]] ], [ @f2, [[COND_END11_FOLD_SPLIT]] ], [ @f3, [[COND_END11_FOLD_SPLIT1]] ] +; DISABLE-NEXT: [[CALL:%.*]] = call i32 [[COND12]](i32 [[B:%.*]], i32 [[C:%.*]]) +; DISABLE-NEXT: ret i32 [[CALL]] +; entry: %cmp = icmp eq i32 %a, 1 br i1 %cmp, label %cond.end11, label %cond.false diff --git a/llvm/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll b/llvm/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll index a8758a78..adb0a98 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/disable-lookup-table.ll +++ b/llvm/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 @@ return: 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 diff --git a/llvm/test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll b/llvm/test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll index bee80e6..11ba398 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll +++ b/llvm/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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true 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 @@ cond.end: ; preds = %entry, %cond.true 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 @@ cond.end: ; preds = %entry, %cond.true 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 @@ cond.end: ; preds = %entry, %cond.true 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 @@ cond.end: ; preds = %entry, %cond.true ; 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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true } 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 @@ cond.end: ; preds = %entry, %cond.true } 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 diff --git a/llvm/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll b/llvm/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll index c42568f..b7bf805 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/switch-covered-bug.ll +++ b/llvm/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 @@ -5,25 +6,24 @@ target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-darwin12.0.0" -; When we have a covered lookup table, make sure we don't delete PHINodes that -; are cached in PHIs. -; CHECK-LABEL: @test -; CHECK: entry: -; CHECK-NEXT: sub i3 %arg, -4 -; CHECK-NEXT: zext i3 %switch.tableidx to i4 -; CHECK-NEXT: getelementptr inbounds [8 x i64], [8 x i64]* @switch.table.test, i32 0, i4 %switch.tableidx.zext -; CHECK-NEXT: load i64, i64* %switch.gep -; 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: diff --git a/llvm/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll b/llvm/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll index 0b9d6eb..e50a913f 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/switch-table-bug.ll +++ b/llvm/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 @@ -5,21 +6,21 @@ target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-darwin12.0.0" -; When tableindex can't fit into i2, we should extend the type to i3. -; CHECK-LABEL: @_TFO6reduce1E5toRawfS0_FT_Si -; CHECK: entry: -; CHECK-NEXT: sub i2 %0, -2 -; CHECK-NEXT: zext i2 %switch.tableidx to i3 -; CHECK-NEXT: getelementptr inbounds [4 x i64], [4 x i64]* @switch.table._TFO6reduce1E5toRawfS0_FT_Si, i32 0, i3 %switch.tableidx.zext -; 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 ] ;