1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00
llvm-mirror/test/Analysis/ConstantFolding/smul-fix.ll
Bjorn Pettersson bf5889110e [ConstantFolding] Add constant folding for smul.fix and smul.fix.sat
Summary:
This patch teaches ConstantFolding to constant fold
both scalar and vector variants of llvm.smul.fix and
llvm.smul.fix.sat.

As described in the LangRef rounding is unspecified for
these instrinsics. If the result cannot be represented
exactly the default behavior in ConstantFolding is to
round down towards negative infinity. If a target has a
preferred rounding that is different some kind of target
hook would be needed (same strategy as used by the
SelectionDAG legalizer).

Reviewers: nikic, leonardchan, RKSimon

Reviewed By: leonardchan

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63385

llvm-svn: 363811
2019-06-19 14:28:03 +00:00

123 lines
4.1 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -constprop -S | FileCheck %s
;-----------------------------------------------------------------------------
; Simple test using scalar layout.
;-----------------------------------------------------------------------------
declare i32 @llvm.smul.fix.i32(i32, i32, i32)
define i32 @test_smul_fix_i32_0() {
; CHECK-LABEL: @test_smul_fix_i32_0(
; CHECK-NEXT: ret i32 536870912
;
%r = call i32 @llvm.smul.fix.i32(i32 1073741824, i32 1073741824, i32 31) ; 0.5 * 0.5
ret i32 %r
}
;-----------------------------------------------------------------------------
; More extensive tests based on vectors (basically using the scalar fold
; for each index).
;-----------------------------------------------------------------------------
declare <8 x i3> @llvm.smul.fix.v8i3(<8 x i3>, <8 x i3>, i32)
define <8 x i3> @test_smul_fix_v8i3_0() {
; CHECK-LABEL: @test_smul_fix_v8i3_0(
; CHECK-NEXT: ret <8 x i3> <i3 0, i3 -4, i3 0, i3 -4, i3 0, i3 -4, i3 0, i3 -4>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4>,
i32 0)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_1() {
; CHECK-LABEL: @test_smul_fix_v8i3_1(
; CHECK-NEXT: ret <8 x i3> <i3 0, i3 -2, i3 -4, i3 2, i3 0, i3 -2, i3 -4, i3 2>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4>,
i32 1)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_2() {
; CHECK-LABEL: @test_smul_fix_v8i3_2(
; CHECK-NEXT: ret <8 x i3> <i3 -4, i3 3, i3 2, i3 1, i3 0, i3 -1, i3 -2, i3 -3>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4>,
i32 2)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_3() {
; CHECK-LABEL: @test_smul_fix_v8i3_3(
; CHECK-NEXT: ret <8 x i3> <i3 -4, i3 3, i3 2, i3 1, i3 0, i3 -1, i3 -2, i3 -3>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>,
i32 0)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_4() {
; CHECK-LABEL: @test_smul_fix_v8i3_4(
; CHECK-NEXT: ret <8 x i3> <i3 2, i3 1, i3 1, i3 0, i3 0, i3 -1, i3 -1, i3 -2>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>,
i32 1)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_5() {
; CHECK-LABEL: @test_smul_fix_v8i3_5(
; CHECK-NEXT: ret <8 x i3> <i3 1, i3 0, i3 0, i3 0, i3 0, i3 -1, i3 -1, i3 -1>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>,
i32 2)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_6() {
; CHECK-LABEL: @test_smul_fix_v8i3_6(
; CHECK-NEXT: ret <8 x i3> <i3 -4, i3 -1, i3 2, i3 -3, i3 0, i3 3, i3 -2, i3 1>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3>,
i32 0)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_7() {
; CHECK-LABEL: @test_smul_fix_v8i3_7(
; CHECK-NEXT: ret <8 x i3> <i3 2, i3 3, i3 -3, i3 -2, i3 0, i3 1, i3 3, i3 -4>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3>,
i32 1)
ret <8 x i3> %r
}
define <8 x i3> @test_smul_fix_v8i3_8() {
; CHECK-LABEL: @test_smul_fix_v8i3_8(
; CHECK-NEXT: ret <8 x i3> <i3 -3, i3 -3, i3 -2, i3 -1, i3 0, i3 0, i3 1, i3 2>
;
%r = call <8 x i3> @llvm.smul.fix.v8i3(
<8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
<8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3>,
i32 2)
ret <8 x i3> %r
}