Files
TheRock/compiler/amd-llvm/mlir/unittests/Interfaces/InferIntRangeInterfaceTest.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

100 lines
3.3 KiB
C++

//===- InferIntRangeInterfaceTest.cpp - Unit Tests for InferIntRange... --===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Interfaces/InferIntRangeInterface.h"
#include "llvm/ADT/APInt.h"
#include <limits>
#include <gtest/gtest.h>
using namespace mlir;
TEST(IntRangeAttrs, BasicConstructors) {
APInt zero = APInt::getZero(64);
APInt two(64, 2);
APInt three(64, 3);
ConstantIntRanges boundedAbove(zero, two, zero, three);
EXPECT_EQ(boundedAbove.umin(), zero);
EXPECT_EQ(boundedAbove.umax(), two);
EXPECT_EQ(boundedAbove.smin(), zero);
EXPECT_EQ(boundedAbove.smax(), three);
}
TEST(IntRangeAttrs, FromUnsigned) {
APInt zero = APInt::getZero(64);
APInt maxInt = APInt::getSignedMaxValue(64);
APInt minInt = APInt::getSignedMinValue(64);
APInt minIntPlusOne = minInt + 1;
ConstantIntRanges canPortToSigned =
ConstantIntRanges::fromUnsigned(zero, maxInt);
EXPECT_EQ(canPortToSigned.smin(), zero);
EXPECT_EQ(canPortToSigned.smax(), maxInt);
ConstantIntRanges cantPortToSigned =
ConstantIntRanges::fromUnsigned(zero, minInt);
EXPECT_EQ(cantPortToSigned.smin(), minInt);
EXPECT_EQ(cantPortToSigned.smax(), maxInt);
ConstantIntRanges signedNegative =
ConstantIntRanges::fromUnsigned(minInt, minIntPlusOne);
EXPECT_EQ(signedNegative.smin(), minInt);
EXPECT_EQ(signedNegative.smax(), minIntPlusOne);
}
TEST(IntRangeAttrs, FromSigned) {
APInt zero = APInt::getZero(64);
APInt one = zero + 1;
APInt negOne = zero - 1;
APInt intMax = APInt::getSignedMaxValue(64);
APInt intMin = APInt::getSignedMinValue(64);
APInt uintMax = APInt::getMaxValue(64);
ConstantIntRanges noUnsignedBound =
ConstantIntRanges::fromSigned(negOne, one);
EXPECT_EQ(noUnsignedBound.umin(), zero);
EXPECT_EQ(noUnsignedBound.umax(), uintMax);
ConstantIntRanges positive = ConstantIntRanges::fromSigned(one, intMax);
EXPECT_EQ(positive.umin(), one);
EXPECT_EQ(positive.umax(), intMax);
ConstantIntRanges negative = ConstantIntRanges::fromSigned(intMin, negOne);
EXPECT_EQ(negative.umin(), intMin);
EXPECT_EQ(negative.umax(), negOne);
ConstantIntRanges preserved = ConstantIntRanges::fromSigned(zero, one);
EXPECT_EQ(preserved.umin(), zero);
EXPECT_EQ(preserved.umax(), one);
}
TEST(IntRangeAttrs, Join) {
APInt zero = APInt::getZero(64);
APInt one = zero + 1;
APInt two = zero + 2;
APInt intMin = APInt::getSignedMinValue(64);
APInt intMax = APInt::getSignedMaxValue(64);
APInt uintMax = APInt::getMaxValue(64);
ConstantIntRanges maximal(zero, uintMax, intMin, intMax);
ConstantIntRanges zeroOne(zero, one, zero, one);
EXPECT_EQ(zeroOne.rangeUnion(maximal), maximal);
EXPECT_EQ(maximal.rangeUnion(zeroOne), maximal);
EXPECT_EQ(zeroOne.rangeUnion(zeroOne), zeroOne);
ConstantIntRanges oneTwo(one, two, one, two);
ConstantIntRanges zeroTwo(zero, two, zero, two);
EXPECT_EQ(zeroOne.rangeUnion(oneTwo), zeroTwo);
ConstantIntRanges zeroOneUnsignedOnly(zero, one, intMin, intMax);
ConstantIntRanges zeroOneSignedOnly(zero, uintMax, zero, one);
EXPECT_EQ(zeroOneUnsignedOnly.rangeUnion(zeroOneSignedOnly), maximal);
}