From 3fedc1009009d7f2e8a7e66a615c6b34c6f91969 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 5 Jan 2021 14:57:07 +0300 Subject: [PATCH] [NFC][SimplifyCFG] Add a test with same-destination condidional branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by Mikael Holmén as post-commit feedback on https://reviews.llvm.org/rG2d07414ee5f74a09fb89723b4a9bb0818bdc2e18#968162 --- lib/Transforms/Utils/SimplifyCFG.cpp | 6 +-- ...ional-branch-with-matching-destinations.ll | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index d01d9512212..cf4854d27f4 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4690,9 +4690,9 @@ bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) { Changed = true; } else { Value* Cond = BI->getCondition(); - assert(BI->getSuccessor(0) != BI->getSuccessor(1) && - "Same-destination conditional branch instruction was " - "already canonicalized into an unconditional branch."); + // assert(BI->getSuccessor(0) != BI->getSuccessor(1) && + // "Same-destination conditional branch instruction was " + // "already canonicalized into an unconditional branch."); if (BI->getSuccessor(0) == BB) { Builder.CreateAssumption(Builder.CreateNot(Cond)); Builder.CreateBr(BI->getSuccessor(1)); diff --git a/test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll b/test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll new file mode 100644 index 00000000000..b56d9d43592 --- /dev/null +++ b/test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll @@ -0,0 +1,48 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=0 < %s | FileCheck %s + +@global = external global i16, align 1 +@global.1 = external global i16, align 1 +@global.2 = external global i16, align 1 + +define void @widget() { +; CHECK-LABEL: @widget( +; CHECK-NEXT: bb: +; CHECK-NEXT: [[I:%.*]] = load i16, i16* @global, align 1 +; CHECK-NEXT: [[I13:%.*]] = icmp ne i16 [[I]], 0 +; CHECK-NEXT: call void @llvm.assume(i1 [[I13]]) +; CHECK-NEXT: [[I17:%.*]] = load i16, i16* @global, align 1 +; CHECK-NEXT: [[I18:%.*]] = sdiv i16 2, [[I17]] +; CHECK-NEXT: [[I19:%.*]] = icmp ne i16 [[I18]], 0 +; CHECK-NEXT: [[I20:%.*]] = zext i1 [[I19]] to i16 +; CHECK-NEXT: [[I21:%.*]] = load i16, i16* @global.1, align 1 +; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[I19]], i16 [[I20]], i16 [[I21]] +; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[I19]], true +; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]]) +; CHECK-NEXT: unreachable +; +bb: + %i = load i16, i16* @global, align 1 + %i13 = icmp ne i16 %i, 0 + br i1 %i13, label %bb16, label %bb14 + +bb14: ; preds = %bb + %i15 = load i16, i16* @global.1, align 1 + br label %bb23 + +bb16: ; preds = %bb + %i17 = load i16, i16* @global, align 1 + %i18 = sdiv i16 2, %i17 + %i19 = icmp ne i16 %i18, 0 + %i20 = zext i1 %i19 to i16 + %i21 = load i16, i16* @global.1, align 1 + br i1 %i19, label %bb22, label %bb23 + +bb22: ; preds = %bb16 + br label %bb23 + +bb23: ; preds = %bb22, %bb16, %bb14 + %i24 = phi i16 [ %i20, %bb22 ], [ %i21, %bb16 ], [ %i15, %bb14 ] + store i16 %i24, i16* @global.2, align 1 + unreachable +}