Added an additional check for constants after simplification of "select _, true, false" pattern. We need to prevent attempts to unswitch constant conditions for two reasons: a) Doing that doesn't make any sense, in the best case it will just burn some compile time. b) SimpleLoopUnswitch isn't designed to unswitch constant conditions (due to (a)), so attempting that can cause miscompiles. The attached testcase is an example of such miscompile. Also added an assertion that'll make sure we aren't trying to replace constants, so it will help us prevent such bugs in future. The assertion from D110751 is another layer of protection against such cases. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D110752
33 lines
798 B
LLVM
33 lines
798 B
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -passes='simple-loop-unswitch<nontrivial>' -S < %s | FileCheck %s
|
|
|
|
; If we try to replace uses of `true` outside of `@foo`, we'll see it here.
|
|
define i1 @bar() {
|
|
; CHECK-LABEL: @bar(
|
|
; CHECK-NEXT: ret i1 true
|
|
;
|
|
ret i1 true
|
|
}
|
|
|
|
; We shouldn't unswitch this loop.
|
|
define void @foo() {
|
|
; CHECK-LABEL: @foo(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: br label [[HEADER:%.*]]
|
|
; CHECK: header:
|
|
; CHECK-NEXT: [[VAL:%.*]] = select i1 true, i1 true, i1 false
|
|
; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[HEADER]]
|
|
; CHECK: exit:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
br label %header
|
|
|
|
header:
|
|
%val = select i1 true, i1 true, i1 false
|
|
br i1 %val, label %exit, label %header
|
|
|
|
exit:
|
|
ret void
|
|
}
|