
Currently, m_Mul() style matchers also match constant expressions. This is a regular source of assertion failures (usually by trying to do a match and then cast to Instruction or BinaryOperator) and infinite combine loops. At the same time, I don't think this provides useful optimization capabilities (all of the tests affected here are regression tests for crashes / infinite loops). Long term, all of these constant expressions (apart from possibly add/sub) are slated for removal per https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179 -- but doing those removals can itself expose new crashes and infinite loops due to the current PatternMatch behavior. Differential Revision: https://reviews.llvm.org/D156401
45 lines
1020 B
LLVM
45 lines
1020 B
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
|
|
|
|
@g = global i32 0
|
|
|
|
; PR30486
|
|
define i32 @single_case() {
|
|
; CHECK-LABEL: @single_case(
|
|
; CHECK-NEXT: switch i32 add (i32 ptrtoint (ptr @g to i32), i32 -1), label [[X:%.*]] [
|
|
; CHECK-NEXT: ]
|
|
; CHECK: x:
|
|
; CHECK-NEXT: ret i32 0
|
|
;
|
|
switch i32 add (i32 ptrtoint (ptr @g to i32), i32 -1), label %x []
|
|
x:
|
|
ret i32 0
|
|
}
|
|
|
|
define i32 @multiple_cases() {
|
|
; CHECK-LABEL: @multiple_cases(
|
|
; CHECK-NEXT: switch i32 add (i32 ptrtoint (ptr @g to i32), i32 -1), label [[X:%.*]] [
|
|
; CHECK-NEXT: i32 1, label [[ONE:%.*]]
|
|
; CHECK-NEXT: i32 2, label [[TWO:%.*]]
|
|
; CHECK-NEXT: ]
|
|
; CHECK: x:
|
|
; CHECK-NEXT: ret i32 0
|
|
; CHECK: one:
|
|
; CHECK-NEXT: ret i32 1
|
|
; CHECK: two:
|
|
; CHECK-NEXT: ret i32 2
|
|
;
|
|
switch i32 add (i32 ptrtoint (ptr @g to i32), i32 -1), label %x [
|
|
i32 1, label %one
|
|
i32 2, label %two
|
|
]
|
|
x:
|
|
ret i32 0
|
|
|
|
one:
|
|
ret i32 1
|
|
|
|
two:
|
|
ret i32 2
|
|
}
|