1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[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
This commit is contained in:
Roman Lebedev 2021-01-05 14:57:07 +03:00
parent 5341fe1751
commit 3fedc10090
2 changed files with 51 additions and 3 deletions

View File

@ -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));

View File

@ -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
}