llvm-project/llvm/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll

87 lines
2.5 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -simplifycfg -S | FileCheck %s
; PR10131
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"
define i32 @t(i32 %m) nounwind readnone {
; CHECK-LABEL: @t(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[M:%.*]], 4
; CHECK-NEXT: [[M_:%.*]] = select i1 [[SWITCH]], i32 [[M]], i32 4
; CHECK-NEXT: ret i32 [[M_]]
;
entry:
switch i32 %m, label %sw.bb4 [
i32 0, label %sw.bb0
i32 1, label %sw.bb1
i32 2, label %sw.bb2
i32 3, label %sw.bb3
]
sw.bb0: ; preds = %entry
br label %return
sw.bb1: ; preds = %entry
br label %return
sw.bb2: ; preds = %entry
br label %return
sw.bb3: ; preds = %entry
br label %return
sw.bb4: ; preds = %entry
br label %return
return: ; preds = %entry, %sw.bb4, %sw.bb3, %sw.bb2, %sw.bb1
%retval.0 = phi i32 [ 4, %sw.bb4 ], [ 3, %sw.bb3 ], [ 2, %sw.bb2 ], [ 1, %sw.bb1 ], [ 0, %sw.bb0 ]
ret i32 %retval.0
}
; If 1 incoming phi value is a case constant of a switch, convert it to the switch condition:
; https://bugs.llvm.org/show_bug.cgi?id=34471
; This then subsequently should allow squashing of the other trivial case blocks.
define i32 @PR34471(i32 %x) {
; CHECK-LABEL: @PR34471(
; CHECK-NEXT: entry:
; CHECK-NEXT: switch i32 [[X:%.*]], label [[ELSE3:%.*]] [
; CHECK-NEXT: i32 17, label [[RETURN:%.*]]
; CHECK-NEXT: i32 19, label [[IF19:%.*]]
; CHECK-NEXT: i32 42, label [[IF42:%.*]]
; CHECK-NEXT: ]
; CHECK: if19:
; CHECK-NEXT: br label [[RETURN]]
; CHECK: if42:
; CHECK-NEXT: br label [[RETURN]]
; CHECK: else3:
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[X]], [[IF19]] ], [ [[X]], [[IF42]] ], [ 0, [[ELSE3]] ], [ 17, [[ENTRY:%.*]] ]
; CHECK-NEXT: ret i32 [[R]]
;
entry:
switch i32 %x, label %else3 [
i32 17, label %return
i32 19, label %if19
i32 42, label %if42
]
if19:
br label %return
if42:
br label %return
else3:
br label %return
return:
%r = phi i32 [ %x, %if19 ], [ %x, %if42 ], [ 0, %else3 ], [ 17, %entry ]
ret i32 %r
}