[llvm-branch-commits] [llvm] 3460719 - [NFC][SimplifyCFG] Add a test with same-destination condidional branch

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 5 14:56:52 PST 2021


Author: Roman Lebedev
Date: 2021-01-06T01:52:36+03:00
New Revision: 3460719f583583e6990ec5c1b2a718cc01797bf7

URL: https://github.com/llvm/llvm-project/commit/3460719f583583e6990ec5c1b2a718cc01797bf7
DIFF: https://github.com/llvm/llvm-project/commit/3460719f583583e6990ec5c1b2a718cc01797bf7.diff

LOG: [NFC][SimplifyCFG] Add a test with same-destination condidional branch

Reported by Mikael Holmén as post-commit feedback on
https://reviews.llvm.org/rG2d07414ee5f74a09fb89723b4a9bb0818bdc2e18#968162

Added: 
    llvm/test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index d01d9512212c..cf4854d27f4a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/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/llvm/test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll b/llvm/test/Transforms/SimplifyCFG/simplifyUnreachable-degenerate-conditional-branch-with-matching-destinations.ll
new file mode 100644
index 000000000000..b56d9d435925
--- /dev/null
+++ b/llvm/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
+
+ at global = external global i16, align 1
+ at global.1 = external global i16, align 1
+ at 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
+}


        


More information about the llvm-branch-commits mailing list