llvm-project/llvm/test/Analysis/ConstantFolding/saturating-add-sub.ll

112 lines
4.1 KiB
LLVM
Raw Normal View History

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -constprop -S | FileCheck %s
declare void @dummy(i8)
declare void @dummy_vec(<2 x i8>)
declare i8 @llvm.uadd.sat.i8(i8, i8)
declare i8 @llvm.sadd.sat.i8(i8, i8)
declare <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8>, <2 x i8>)
declare <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8>, <2 x i8>)
declare i8 @llvm.usub.sat.i8(i8, i8)
declare i8 @llvm.ssub.sat.i8(i8, i8)
declare <2 x i8> @llvm.usub.sat.v2i8(<2 x i8>, <2 x i8>)
declare <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8>, <2 x i8>)
define void @test_add_scalar() {
; CHECK-LABEL: @test_add_scalar(
; CHECK-NEXT: call void @dummy(i8 30)
; CHECK-NEXT: call void @dummy(i8 -1)
; CHECK-NEXT: call void @dummy(i8 -10)
; CHECK-NEXT: call void @dummy(i8 127)
; CHECK-NEXT: call void @dummy(i8 -128)
; CHECK-NEXT: ret void
;
%x1 = call i8 @llvm.uadd.sat.i8(i8 10, i8 20)
call void @dummy(i8 %x1)
%x2 = call i8 @llvm.uadd.sat.i8(i8 250, i8 100)
call void @dummy(i8 %x2)
%y1 = call i8 @llvm.sadd.sat.i8(i8 10, i8 -20)
call void @dummy(i8 %y1)
%y2 = call i8 @llvm.sadd.sat.i8(i8 120, i8 10)
call void @dummy(i8 %y2)
%y3 = call i8 @llvm.sadd.sat.i8(i8 -120, i8 -10)
call void @dummy(i8 %y3)
ret void
}
define void @test_add_vector(<2 x i8> %a) {
; CHECK-LABEL: @test_add_vector(
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 20, i8 30>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 -1, i8 -1>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 -10, i8 -30>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 127, i8 127>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 -128, i8 -128>)
; CHECK-NEXT: ret void
;
%x1 = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> <i8 10, i8 15>, <2 x i8> <i8 10, i8 15>)
call void @dummy_vec(<2 x i8> %x1)
%x2 = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> <i8 100, i8 200>, <2 x i8> <i8 250, i8 100>)
call void @dummy_vec(<2 x i8> %x2)
%y1 = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> <i8 10, i8 -15>, <2 x i8> <i8 -20, i8 -15>)
call void @dummy_vec(<2 x i8> %y1)
%y2 = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> <i8 100, i8 10>, <2 x i8> <i8 30, i8 120>)
call void @dummy_vec(<2 x i8> %y2)
%y3 = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> <i8 -100, i8 -10>, <2 x i8> <i8 -30, i8 -120>)
call void @dummy_vec(<2 x i8> %y3)
ret void
}
define void @test_usub_ssub_scalar() {
; CHECK-LABEL: @test_usub_ssub_scalar(
; CHECK-NEXT: call void @dummy(i8 10)
; CHECK-NEXT: call void @dummy(i8 0)
; CHECK-NEXT: call void @dummy(i8 -30)
; CHECK-NEXT: call void @dummy(i8 127)
; CHECK-NEXT: call void @dummy(i8 -128)
; CHECK-NEXT: ret void
;
%x1 = call i8 @llvm.usub.sat.i8(i8 20, i8 10)
call void @dummy(i8 %x1)
%x2 = call i8 @llvm.usub.sat.i8(i8 200, i8 250)
call void @dummy(i8 %x2)
%y1 = call i8 @llvm.ssub.sat.i8(i8 -10, i8 20)
call void @dummy(i8 %y1)
%y2 = call i8 @llvm.ssub.sat.i8(i8 120, i8 -10)
call void @dummy(i8 %y2)
%y3 = call i8 @llvm.ssub.sat.i8(i8 -120, i8 10)
call void @dummy(i8 %y3)
ret void
}
define void @test_sub_vector(<2 x i8> %a) {
; CHECK-LABEL: @test_sub_vector(
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 10, i8 5>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> zeroinitializer)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 30, i8 0>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 127, i8 127>)
; CHECK-NEXT: call void @dummy_vec(<2 x i8> <i8 -128, i8 -128>)
; CHECK-NEXT: ret void
;
%x1 = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> <i8 20, i8 15>, <2 x i8> <i8 10, i8 10>)
call void @dummy_vec(<2 x i8> %x1)
%x2 = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> <i8 100, i8 200>, <2 x i8> <i8 150, i8 250>)
call void @dummy_vec(<2 x i8> %x2)
%y1 = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 10, i8 -15>, <2 x i8> <i8 -20, i8 -15>)
call void @dummy_vec(<2 x i8> %y1)
%y2 = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 100, i8 10>, <2 x i8> <i8 -30, i8 -120>)
call void @dummy_vec(<2 x i8> %y2)
%y3 = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 -100, i8 -10>, <2 x i8> <i8 30, i8 120>)
call void @dummy_vec(<2 x i8> %y3)
ret void
}