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
95 lines
3.5 KiB
C++
95 lines
3.5 KiB
C++
//===- RegAllocBasicTest.cpp - Tests for basic register allocator --------===//
|
|
//
|
|
// 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 "../../lib/CodeGen/RegAllocBasic.h"
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
|
#include "gtest/gtest.h"
|
|
#include <queue>
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
TEST(RegAllocBasicTest, CompSpillWeightDeterminism) {
|
|
// Test that CompSpillWeight provides deterministic ordering by testing
|
|
// all valid combinations of weight and register number comparisons.
|
|
//
|
|
// This is a regression test for non-deterministic behavior that occurred
|
|
// when ASAN changed memory layout, causing different heap configurations
|
|
// for LiveIntervals with identical spill weights.
|
|
//
|
|
// Comparison has two components: (weight, register number)
|
|
// Each can be <, =, or > resulting in 9 total combinations, but the case
|
|
// where register is equal and weight is different is impossible because each
|
|
// virtual register has exactly one LiveInterval with one weight.
|
|
|
|
// Create 3 LiveIntervals to test all 7 valid comparison combinations.
|
|
// Layout: W{weight}R{register}
|
|
LiveInterval W1R10(Register::index2VirtReg(10), 1.0f);
|
|
LiveInterval W1R30(Register::index2VirtReg(30), 1.0f);
|
|
LiveInterval W2R20(Register::index2VirtReg(20), 2.0f);
|
|
|
|
CompSpillWeight IsLessThan;
|
|
|
|
// Test all meaningful combinations of (weight comparison, register
|
|
// comparison). IsLessThan(A, B) returns true if A has lower priority than B
|
|
// (A < B in max-heap)
|
|
|
|
// Case 1: weight <, reg < : A has lower priority (weight dominates)
|
|
EXPECT_TRUE(IsLessThan(&W1R10, &W2R20));
|
|
EXPECT_FALSE(IsLessThan(&W2R20, &W1R10));
|
|
|
|
// Case 2: weight <, reg > : A has lower priority (weight dominates)
|
|
EXPECT_TRUE(IsLessThan(&W1R30, &W2R20));
|
|
EXPECT_FALSE(IsLessThan(&W2R20, &W1R30));
|
|
|
|
// Case 3: weight =, reg < : A has lower priority (register breaks tie)
|
|
EXPECT_TRUE(IsLessThan(&W1R10, &W1R30));
|
|
EXPECT_FALSE(IsLessThan(&W1R30, &W1R10));
|
|
|
|
// Case 4: weight =, reg = : equal (both comparisons return false)
|
|
EXPECT_FALSE(IsLessThan(&W1R10, &W1R10));
|
|
|
|
// Case 5: weight =, reg > : A has higher priority (register breaks tie)
|
|
EXPECT_FALSE(IsLessThan(&W1R30, &W1R10));
|
|
EXPECT_TRUE(IsLessThan(&W1R10, &W1R30));
|
|
|
|
// Case 6: weight >, reg < : A has higher priority (weight dominates)
|
|
EXPECT_FALSE(IsLessThan(&W2R20, &W1R30));
|
|
EXPECT_TRUE(IsLessThan(&W1R30, &W2R20));
|
|
|
|
// Case 7: weight >, reg > : A has higher priority (weight dominates)
|
|
EXPECT_FALSE(IsLessThan(&W2R20, &W1R10));
|
|
EXPECT_TRUE(IsLessThan(&W1R10, &W2R20));
|
|
|
|
// Test priority_queue ordering with all intervals
|
|
std::priority_queue<const LiveInterval *, std::vector<const LiveInterval *>,
|
|
CompSpillWeight>
|
|
PQ;
|
|
|
|
// Insert all intervals in arbitrary order
|
|
PQ.push(&W1R30);
|
|
PQ.push(&W2R20);
|
|
PQ.push(&W1R10);
|
|
|
|
// Expected order: highest weight first, then descending register within ties
|
|
// Weight 2.0: R20
|
|
EXPECT_EQ(PQ.top()->reg(), Register::index2VirtReg(20));
|
|
EXPECT_EQ(PQ.top()->weight(), 2.0f);
|
|
PQ.pop();
|
|
|
|
// Weight 1.0: R30, R10 (descending register order)
|
|
EXPECT_EQ(PQ.top()->reg(), Register::index2VirtReg(30));
|
|
EXPECT_EQ(PQ.top()->weight(), 1.0f);
|
|
PQ.pop();
|
|
EXPECT_EQ(PQ.top()->reg(), Register::index2VirtReg(10));
|
|
EXPECT_EQ(PQ.top()->weight(), 1.0f);
|
|
}
|
|
|
|
} // anonymous namespace
|