1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00
llvm-mirror/test/Transforms/CorrelatedValuePropagation/minmaxabs.ll
Roman Lebedev 8028ab057e [CVP] @llvm.abs() handling
Iff we know the sigdness domain of the argument,
we can either skip @llvm.abs, or do negation directly.

Notably, INT_MIN can belong to either domain:
* X u<= INT_MIN --> X  is always fine
  https://alive2.llvm.org/ce/z/QB8j-C https://alive2.llvm.org/ce/z/7sFKpS
* X s<= 0 --> -X  is always fine
  https://alive2.llvm.org/ce/z/QbGSyq https://alive2.llvm.org/ce/z/APsN84

If all else fails, try to inferr NSW flag:
https://alive2.llvm.org/ce/z/qCJfYm
2021-04-10 16:47:31 +03:00

124 lines
3.7 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -correlated-propagation < %s | FileCheck %s
declare i32 @llvm.umin.i32(i32, i32)
declare i32 @llvm.umax.i32(i32, i32)
declare i32 @llvm.smin.i32(i32, i32)
declare i32 @llvm.smax.i32(i32, i32)
declare i32 @llvm.abs.i32(i32, i1)
declare void @use(i1)
define void @test_umin(i32 %x) {
; CHECK-LABEL: @test_umin(
; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.umin.i32(i32 [[X:%.*]], i32 10)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[M]], 10
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%m = call i32 @llvm.umin.i32(i32 %x, i32 10)
%c1 = icmp ule i32 %m, 10
call void @use(i1 %c1)
%c2 = icmp ult i32 %m, 10
call void @use(i1 %c2)
ret void
}
define void @test_umax(i32 %x) {
; CHECK-LABEL: @test_umax(
; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.umax.i32(i32 [[X:%.*]], i32 10)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp ugt i32 [[M]], 10
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%m = call i32 @llvm.umax.i32(i32 %x, i32 10)
%c1 = icmp uge i32 %m, 10
call void @use(i1 %c1)
%c2 = icmp ugt i32 %m, 10
call void @use(i1 %c2)
ret void
}
define void @test_smin(i32 %x) {
; CHECK-LABEL: @test_smin(
; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 10)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[M]], 10
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%m = call i32 @llvm.smin.i32(i32 %x, i32 10)
%c1 = icmp sle i32 %m, 10
call void @use(i1 %c1)
%c2 = icmp slt i32 %m, 10
call void @use(i1 %c2)
ret void
}
define void @test_smax(i32 %x) {
; CHECK-LABEL: @test_smax(
; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.smax.i32(i32 [[X:%.*]], i32 10)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[M]], 10
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%m = call i32 @llvm.smax.i32(i32 %x, i32 10)
%c1 = icmp sge i32 %m, 10
call void @use(i1 %c1)
%c2 = icmp sgt i32 %m, 10
call void @use(i1 %c2)
ret void
}
define void @test_abs1(i32* %p) {
; CHECK-LABEL: @test_abs1(
; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4, !range [[RNG0:![0-9]+]]
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X]], i1 true)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[A]], 15
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%x = load i32, i32* %p, !range !{i32 -15, i32 10}
%a = call i32 @llvm.abs.i32(i32 %x, i1 false)
%c1 = icmp ule i32 %a, 15
call void @use(i1 %c1)
%c2 = icmp ult i32 %a, 15
call void @use(i1 %c2)
ret void
}
define void @test_abs2(i32 %x) {
; CHECK-LABEL: @test_abs2(
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[A]], -2147483648
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%a = call i32 @llvm.abs.i32(i32 %x, i1 false)
%c1 = icmp ule i32 %a, 2147483648
call void @use(i1 %c1)
%c2 = icmp ult i32 %a, 2147483648
call void @use(i1 %c2)
ret void
}
define void @test_abs3(i32 %x) {
; CHECK-LABEL: @test_abs3(
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[A]], 0
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void
;
%a = call i32 @llvm.abs.i32(i32 %x, i1 true)
%c1 = icmp sge i32 %a, 0
call void @use(i1 %c1)
%c2 = icmp sgt i32 %a, 0
call void @use(i1 %c2)
ret void
}