1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00
Florian Hahn 3798c57e6c [SCCP] Use constant ranges for select, if cond is overdefined.
For selects with an unknown condition, we can approximate the result by
merging the state of both options. This automatically takes care of
the case where on operand is undef.

Reviewers: davide, efriedma, mssimpso

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D71935
2020-03-18 09:26:02 +00:00

41 lines
1.1 KiB
LLVM

; RUN: opt < %s -sccp -S | FileCheck %s
define i32 @test1(i1 %C) {
; CHECK-LABEL: define i32 @test1(
; CHECK-NEXT: ret i32 0
;
%X = select i1 %C, i32 0, i32 0 ; <i32> [#uses=1]
ret i32 %X
}
define i32 @test2(i1 %C) {
; CHECK-LABEL: define i32 @test2(
; CHECK-NEXT: ret i32 0
;
%X = select i1 %C, i32 0, i32 undef ; <i32> [#uses=1]
ret i32 %X
}
define i1 @f2(i32 %x, i1 %cmp) {
; CHECK-LABEL: define i1 @f2(i32 %x, i1 %cmp) {
; CHECK-NEXT: %sel.1 = select i1 %cmp, i32 %x, i32 10
; CHECK-NEXT: %c.1 = icmp sgt i32 %sel.1, 300
; CHECK-NEXT: %c.2 = icmp sgt i32 %sel.1, 100
; CHECK-NEXT: %c.3 = icmp eq i32 %sel.1, 50
; CHECK-NEXT: %c.4 = icmp slt i32 %sel.1, 9
; CHECK-NEXT: %res.1 = add i1 %c.1, %c.2
; CHECK-NEXT: %res.2 = add i1 %res.1, %c.3
; CHECK-NEXT: %res.3 = add i1 %res.2, %c.4
; CHECK-NEXT: ret i1 %res.3
;
%sel.1 = select i1 %cmp, i32 %x, i32 10
%c.1 = icmp sgt i32 %sel.1, 300
%c.2 = icmp sgt i32 %sel.1, 100
%c.3 = icmp eq i32 %sel.1, 50
%c.4 = icmp slt i32 %sel.1, 9
%res.1 = add i1 %c.1, %c.2
%res.2 = add i1 %res.1, %c.3
%res.3 = add i1 %res.2, %c.4
ret i1 %res.3
}