From 93da5978f1600c000cfcc14507d5056cd23ddf3d Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Mon, 13 Jan 2025 20:47:15 +0000 Subject: [PATCH 01/16] add power function --- llvm/include/llvm/ADT/APFloat.h | 20 ++++++++++++++++++++ llvm/include/llvm/ADT/APInt.h | 3 +++ llvm/lib/Support/APInt.cpp | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h index bf80fa5a06580..236469d43678f 100644 --- a/llvm/include/llvm/ADT/APFloat.h +++ b/llvm/include/llvm/ADT/APFloat.h @@ -1531,6 +1531,26 @@ inline APFloat abs(APFloat X) { return X; } +/// Returns X^N for N >= 0. +inline APFloat pow(const APFloat &X, const int &N) { + assert(N >= 0 && "negative exponents not supported."); + if (N == 0) { + return APFloat::getOne(X.getSemantics()); + } + APFloat Acc = X; + int64_t RemainingExponent = N; + while (RemainingExponent > 1) { + if (RemainingExponent % 2 == 0) { + Acc = Acc * Acc; + RemainingExponent /= 2; + } else { + Acc = Acc * X; + RemainingExponent--; + } + } + return Acc; +}; + /// Returns the negated value of the argument. inline APFloat neg(APFloat X) { X.changeSign(); diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 225390f1af60b..e93f175987568 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -2263,6 +2263,9 @@ APInt mulhs(const APInt &C1, const APInt &C2); /// Returns the high N bits of the multiplication result. APInt mulhu(const APInt &C1, const APInt &C2); +/// Compute X^N for N>0. +APInt pow(const APInt &X, const int &N); + /// Compute GCD of two unsigned APInt values. /// /// This function returns the greatest common divisor of the two APInt values diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index ea8295f95c751..d95c1bc8e7194 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -3108,3 +3108,22 @@ APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) { APInt C2Ext = C2.zext(FullWidth); return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth()); } + +APInt APIntOps::pow(const APInt &X, const int &N) { + assert(N >= 0 && "negative exponents not supported."); + if (N == 0) { + return APInt(X.getBitWidth(), 1); + } + APInt Acc = X; + int64_t RemainingExponent = N; + while (RemainingExponent > 1) { + if (RemainingExponent % 2 == 0) { + Acc = Acc * Acc; + RemainingExponent /= 2; + } else { + Acc = Acc * X; + RemainingExponent--; + } + } + return Acc; +}; From 3a8a0881cc3fd662ab3620d1de3d9b9638cd1771 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Mon, 13 Jan 2025 21:18:22 +0000 Subject: [PATCH 02/16] int -> int64_t --- llvm/include/llvm/ADT/APFloat.h | 2 +- llvm/include/llvm/ADT/APInt.h | 2 +- llvm/lib/Support/APInt.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h index 236469d43678f..b6c5613eb4356 100644 --- a/llvm/include/llvm/ADT/APFloat.h +++ b/llvm/include/llvm/ADT/APFloat.h @@ -1532,7 +1532,7 @@ inline APFloat abs(APFloat X) { } /// Returns X^N for N >= 0. -inline APFloat pow(const APFloat &X, const int &N) { +inline APFloat pow(const APFloat &X, int64_t N) { assert(N >= 0 && "negative exponents not supported."); if (N == 0) { return APFloat::getOne(X.getSemantics()); diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index e93f175987568..167a8459ef64f 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -2264,7 +2264,7 @@ APInt mulhs(const APInt &C1, const APInt &C2); APInt mulhu(const APInt &C1, const APInt &C2); /// Compute X^N for N>0. -APInt pow(const APInt &X, const int &N); +APInt pow(const APInt &X, int64_t N); /// Compute GCD of two unsigned APInt values. /// diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index d95c1bc8e7194..527fc9b51cb65 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -3109,7 +3109,7 @@ APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) { return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth()); } -APInt APIntOps::pow(const APInt &X, const int &N) { +APInt APIntOps::pow(const APInt &X, int64_t N) { assert(N >= 0 && "negative exponents not supported."); if (N == 0) { return APInt(X.getBitWidth(), 1); From 40f5262da320f5ebbb3f8b125943241723993ed9 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 10:27:02 +0000 Subject: [PATCH 03/16] undo APFloat change --- llvm/include/llvm/ADT/APFloat.h | 20 -------------------- llvm/include/llvm/ADT/APInt.h | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h index b6c5613eb4356..bf80fa5a06580 100644 --- a/llvm/include/llvm/ADT/APFloat.h +++ b/llvm/include/llvm/ADT/APFloat.h @@ -1531,26 +1531,6 @@ inline APFloat abs(APFloat X) { return X; } -/// Returns X^N for N >= 0. -inline APFloat pow(const APFloat &X, int64_t N) { - assert(N >= 0 && "negative exponents not supported."); - if (N == 0) { - return APFloat::getOne(X.getSemantics()); - } - APFloat Acc = X; - int64_t RemainingExponent = N; - while (RemainingExponent > 1) { - if (RemainingExponent % 2 == 0) { - Acc = Acc * Acc; - RemainingExponent /= 2; - } else { - Acc = Acc * X; - RemainingExponent--; - } - } - return Acc; -}; - /// Returns the negated value of the argument. inline APFloat neg(APFloat X) { X.changeSign(); diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 167a8459ef64f..81ac17c87a901 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -2263,7 +2263,7 @@ APInt mulhs(const APInt &C1, const APInt &C2); /// Returns the high N bits of the multiplication result. APInt mulhu(const APInt &C1, const APInt &C2); -/// Compute X^N for N>0. +/// Compute X^N for N>=0. APInt pow(const APInt &X, int64_t N); /// Compute GCD of two unsigned APInt values. From 073727cc0167db19eaa0ed6864674bb8c1805879 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 10:41:55 +0000 Subject: [PATCH 04/16] Add unit tests. --- llvm/unittests/ADT/APIntTest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 4d5553fcbd1e3..89dd01e71771e 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -29,6 +29,29 @@ TEST(APIntTest, ValueInit) { EXPECT_TRUE(!Zero.sext(64)); } +// Test that 0^5 == 0 +TEST(APIntTest, PowZeroTo5) { + APInt Zero = APInt(); + EXPECT_TRUE(!Zero); + APInt ZeroTo5 = APIntOps::pow(Zero, 5); + EXPECT_TRUE(!ZeroTo5); +} + +// Test that 1^16 == 1 +TEST(APIntTest, PowOneTo16) { + APInt One = APInt::getZero(32) + 1; + APInt OneTo16 = APIntOps::pow(One, 16); + EXPECT_EQ(One, OneTo16); +} + +// Test that 2^10 == 1024 +TEST(APIntTest, PowerTwoTo10) { + APInt Two = APInt::getZero(32) + 2; + APInt TwoTo20 = APIntOps::pow(Two, 10); + APInt V_1024 = APInt::getZero(32) + 1024; + EXPECT_EQ(TwoTo20, V_1024); +} + // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0 TEST(APIntTest, ShiftLeftByZero) { APInt One = APInt::getZero(65) + 1; From 77d8c07deeb1c7ca1d5f35324a2a4752f1383392 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 11:26:19 +0000 Subject: [PATCH 05/16] Add test. Change impl. --- llvm/lib/Support/APInt.cpp | 16 ++++++++-------- llvm/unittests/ADT/APIntTest.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 527fc9b51cb65..eb6692ad393d7 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -3111,19 +3111,19 @@ APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) { APInt APIntOps::pow(const APInt &X, int64_t N) { assert(N >= 0 && "negative exponents not supported."); + APInt Acc = APInt(X.getBitWidth(), 1); if (N == 0) { - return APInt(X.getBitWidth(), 1); + return Acc; } - APInt Acc = X; + APInt Base = X; int64_t RemainingExponent = N; - while (RemainingExponent > 1) { - if (RemainingExponent % 2 == 0) { - Acc = Acc * Acc; + while (RemainingExponent > 0) { + while (RemainingExponent % 2 == 0) { + Base = Base * Base; RemainingExponent /= 2; - } else { - Acc = Acc * X; - RemainingExponent--; } + --RemainingExponent; + Acc = Acc * Base; } return Acc; }; diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 89dd01e71771e..a5009761fd6c0 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -52,6 +52,14 @@ TEST(APIntTest, PowerTwoTo10) { EXPECT_EQ(TwoTo20, V_1024); } +// Test that 3^3 == 27 +TEST(APIntTest, PowerThreeTo3) { + APInt Three = APInt::getZero(32) + 3; + APInt ThreeTo3 = APIntOps::pow(Three, 3); + APInt V_27 = APInt::getZero(32) + 27; + EXPECT_EQ(ThreeTo3, V_27); +} + // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0 TEST(APIntTest, ShiftLeftByZero) { APInt One = APInt::getZero(65) + 1; From a30e29fedb287f407309204cf0d16f07c9fe9b9b Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 13:34:40 +0000 Subject: [PATCH 06/16] Test (Signed)MaxValue --- llvm/unittests/ADT/APIntTest.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index a5009761fd6c0..7fe5fad747986 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -60,6 +60,20 @@ TEST(APIntTest, PowerThreeTo3) { EXPECT_EQ(ThreeTo3, V_27); } +// Test that SignedMaxValue^3 == SignedMaxValue +TEST(APIntTest, PowerSignedMaxValue) { + APInt SignedMaxValue = APInt::getSignedMaxValue(32); + APInt MaxTo3 = APIntOps::pow(SignedMaxValue, 3); + EXPECT_EQ(MaxTo3, SignedMaxValue); +} + +// Test that MaxValue^3 == MaxValue +TEST(APIntTest, PowerMaxValue) { + APInt MaxValue = APInt::getMaxValue(32); + APInt MaxTo3 = APIntOps::pow(MaxValue, 3); + EXPECT_EQ(MaxValue, MaxTo3); +} + // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0 TEST(APIntTest, ShiftLeftByZero) { APInt One = APInt::getZero(65) + 1; From 13cfbb3f891e3d7c252a0da29fbb476424a7a192 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 15:31:00 +0000 Subject: [PATCH 07/16] Test 0^0 == 1 --- llvm/unittests/ADT/APIntTest.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 7fe5fad747986..3bdfafcd395b3 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -74,6 +74,14 @@ TEST(APIntTest, PowerMaxValue) { EXPECT_EQ(MaxValue, MaxTo3); } +// Test that MaxValue^3 == MaxValue +TEST(APIntTest, ZeroToZero) { + APInt Zero = APInt::getZero(32); + APInt One = APInt::getZero(32) + 1; + APInt ZeroToZero = APIntOps::pow(Zero, 0); + EXPECT_EQ(ZeroToZero, One); +} + // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0 TEST(APIntTest, ShiftLeftByZero) { APInt One = APInt::getZero(65) + 1; From 34d9b963bee7495ee826a260a7d06f5452f83d05 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 16:02:46 +0000 Subject: [PATCH 08/16] 0^0 returns 1 --- llvm/include/llvm/ADT/APInt.h | 1 + llvm/unittests/ADT/APIntTest.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 81ac17c87a901..9e97cf85a47e7 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -2264,6 +2264,7 @@ APInt mulhs(const APInt &C1, const APInt &C2); APInt mulhu(const APInt &C1, const APInt &C2); /// Compute X^N for N>=0. +/// 0^0 would return 1. APInt pow(const APInt &X, int64_t N); /// Compute GCD of two unsigned APInt values. diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 3bdfafcd395b3..3779e652d4e7f 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -74,7 +74,7 @@ TEST(APIntTest, PowerMaxValue) { EXPECT_EQ(MaxValue, MaxTo3); } -// Test that MaxValue^3 == MaxValue +// Test that 0^0 == 1 TEST(APIntTest, ZeroToZero) { APInt Zero = APInt::getZero(32); APInt One = APInt::getZero(32) + 1; From d02314b8d2f157c90bde87b43b07e45fd0cacf30 Mon Sep 17 00:00:00 2001 From: Iman Hosseini Date: Tue, 14 Jan 2025 17:25:55 +0000 Subject: [PATCH 09/16] Update llvm/include/llvm/ADT/APInt.h Co-authored-by: Jakub Kuderski --- llvm/include/llvm/ADT/APInt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 9e97cf85a47e7..02d58d8c3d31c 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -2264,7 +2264,7 @@ APInt mulhs(const APInt &C1, const APInt &C2); APInt mulhu(const APInt &C1, const APInt &C2); /// Compute X^N for N>=0. -/// 0^0 would return 1. +/// 0^0 is supported and returns 1. APInt pow(const APInt &X, int64_t N); /// Compute GCD of two unsigned APInt values. From 564f2dc7a7a097ecd205bbc2c564f972a277b451 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Tue, 14 Jan 2025 19:31:26 +0000 Subject: [PATCH 10/16] remove parens. --- llvm/lib/Support/APInt.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index eb6692ad393d7..24a0d7108b0f7 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -3112,9 +3112,8 @@ APInt APIntOps::mulhu(const APInt &C1, const APInt &C2) { APInt APIntOps::pow(const APInt &X, int64_t N) { assert(N >= 0 && "negative exponents not supported."); APInt Acc = APInt(X.getBitWidth(), 1); - if (N == 0) { + if (N == 0) return Acc; - } APInt Base = X; int64_t RemainingExponent = N; while (RemainingExponent > 0) { From e90a9c87f7c54b98d4915d47107755ff5765ed4b Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Thu, 16 Jan 2025 13:20:32 +0000 Subject: [PATCH 11/16] apply comments. --- llvm/lib/Support/APInt.cpp | 4 ++-- llvm/unittests/ADT/APIntTest.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 24a0d7108b0f7..38cf485733a93 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -3118,11 +3118,11 @@ APInt APIntOps::pow(const APInt &X, int64_t N) { int64_t RemainingExponent = N; while (RemainingExponent > 0) { while (RemainingExponent % 2 == 0) { - Base = Base * Base; + Base *= Base; RemainingExponent /= 2; } --RemainingExponent; - Acc = Acc * Base; + Acc *= Base; } return Acc; }; diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 3779e652d4e7f..c0f1c3480134d 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -39,24 +39,24 @@ TEST(APIntTest, PowZeroTo5) { // Test that 1^16 == 1 TEST(APIntTest, PowOneTo16) { - APInt One = APInt::getZero(32) + 1; + APInt One(32, 1); APInt OneTo16 = APIntOps::pow(One, 16); EXPECT_EQ(One, OneTo16); } // Test that 2^10 == 1024 TEST(APIntTest, PowerTwoTo10) { - APInt Two = APInt::getZero(32) + 2; + APInt Two(32, 2); APInt TwoTo20 = APIntOps::pow(Two, 10); - APInt V_1024 = APInt::getZero(32) + 1024; + APInt V_1024(32, 1024); EXPECT_EQ(TwoTo20, V_1024); } // Test that 3^3 == 27 TEST(APIntTest, PowerThreeTo3) { - APInt Three = APInt::getZero(32) + 3; + APInt Three(32, 3); APInt ThreeTo3 = APIntOps::pow(Three, 3); - APInt V_27 = APInt::getZero(32) + 27; + APInt V_27(32, 27); EXPECT_EQ(ThreeTo3, V_27); } @@ -77,7 +77,7 @@ TEST(APIntTest, PowerMaxValue) { // Test that 0^0 == 1 TEST(APIntTest, ZeroToZero) { APInt Zero = APInt::getZero(32); - APInt One = APInt::getZero(32) + 1; + APInt One(32, 1); APInt ZeroToZero = APIntOps::pow(Zero, 0); EXPECT_EQ(ZeroToZero, One); } From 160dcdb6a23bc92c20c43e7715f740b99aa85085 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Thu, 16 Jan 2025 13:29:42 +0000 Subject: [PATCH 12/16] Add tests. --- llvm/unittests/ADT/APIntTest.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index c0f1c3480134d..83d88d9a4555a 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -39,24 +39,24 @@ TEST(APIntTest, PowZeroTo5) { // Test that 1^16 == 1 TEST(APIntTest, PowOneTo16) { - APInt One(32, 1); + APInt One = APInt::getZero(32) + 1; APInt OneTo16 = APIntOps::pow(One, 16); EXPECT_EQ(One, OneTo16); } // Test that 2^10 == 1024 TEST(APIntTest, PowerTwoTo10) { - APInt Two(32, 2); + APInt Two = APInt::getZero(32) + 2; APInt TwoTo20 = APIntOps::pow(Two, 10); - APInt V_1024(32, 1024); + APInt V_1024 = APInt::getZero(32) + 1024; EXPECT_EQ(TwoTo20, V_1024); } // Test that 3^3 == 27 TEST(APIntTest, PowerThreeTo3) { - APInt Three(32, 3); + APInt Three = APInt::getZero(32) + 3; APInt ThreeTo3 = APIntOps::pow(Three, 3); - APInt V_27(32, 27); + APInt V_27 = APInt::getZero(32) + 27; EXPECT_EQ(ThreeTo3, V_27); } @@ -74,10 +74,24 @@ TEST(APIntTest, PowerMaxValue) { EXPECT_EQ(MaxValue, MaxTo3); } -// Test that 0^0 == 1 +// Test that SignedMinValue^3 == 0 +TEST(APIntTest, PowerSignedMinValueTo3) { + APInt SignedMinValue = APInt::getSignedMinValue(32); + APInt MaxTo3 = APIntOps::pow(SignedMinValue, 3); + EXPECT_TRUE(MaxTo3.isZero()); +} + +// Test that SignedMinValue^1 == SignedMinValue +TEST(APIntTest, PowerSignedMinValueTo1) { + APInt SignedMinValue = APInt::getSignedMinValue(32); + APInt MinTo1 = APIntOps::pow(SignedMinValue, 1); + EXPECT_EQ(SignedMinValue, MinTo1); +} + +// Test that MaxValue^3 == MaxValue TEST(APIntTest, ZeroToZero) { APInt Zero = APInt::getZero(32); - APInt One(32, 1); + APInt One = APInt::getZero(32) + 1; APInt ZeroToZero = APIntOps::pow(Zero, 0); EXPECT_EQ(ZeroToZero, One); } From 3271991e407afac48040cdfe34e2b1286529b16e Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Thu, 16 Jan 2025 19:05:40 +0000 Subject: [PATCH 13/16] max->min --- llvm/unittests/ADT/APIntTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 83d88d9a4555a..16f03517f40d9 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -77,8 +77,8 @@ TEST(APIntTest, PowerMaxValue) { // Test that SignedMinValue^3 == 0 TEST(APIntTest, PowerSignedMinValueTo3) { APInt SignedMinValue = APInt::getSignedMinValue(32); - APInt MaxTo3 = APIntOps::pow(SignedMinValue, 3); - EXPECT_TRUE(MaxTo3.isZero()); + APInt MinTo3 = APIntOps::pow(SignedMinValue, 3); + EXPECT_TRUE(MinTo3.isZero()); } // Test that SignedMinValue^1 == SignedMinValue From ee57ffa51f45a0953ee5310bc0ae0f8fa1a32524 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Thu, 16 Jan 2025 21:34:39 +0000 Subject: [PATCH 14/16] (32, n) constructor. --- llvm/unittests/ADT/APIntTest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 16f03517f40d9..f1aad25d6ec51 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -31,7 +31,7 @@ TEST(APIntTest, ValueInit) { // Test that 0^5 == 0 TEST(APIntTest, PowZeroTo5) { - APInt Zero = APInt(); + APInt Zero = APInt::getZero(32); EXPECT_TRUE(!Zero); APInt ZeroTo5 = APIntOps::pow(Zero, 5); EXPECT_TRUE(!ZeroTo5); @@ -39,14 +39,14 @@ TEST(APIntTest, PowZeroTo5) { // Test that 1^16 == 1 TEST(APIntTest, PowOneTo16) { - APInt One = APInt::getZero(32) + 1; + APInt One(32, 1); APInt OneTo16 = APIntOps::pow(One, 16); EXPECT_EQ(One, OneTo16); } // Test that 2^10 == 1024 TEST(APIntTest, PowerTwoTo10) { - APInt Two = APInt::getZero(32) + 2; + APInt Two(32, 2); APInt TwoTo20 = APIntOps::pow(Two, 10); APInt V_1024 = APInt::getZero(32) + 1024; EXPECT_EQ(TwoTo20, V_1024); @@ -54,9 +54,9 @@ TEST(APIntTest, PowerTwoTo10) { // Test that 3^3 == 27 TEST(APIntTest, PowerThreeTo3) { - APInt Three = APInt::getZero(32) + 3; + APInt Three(32, 3); APInt ThreeTo3 = APIntOps::pow(Three, 3); - APInt V_27 = APInt::getZero(32) + 27; + APInt V_27(32, 27); EXPECT_EQ(ThreeTo3, V_27); } @@ -91,7 +91,7 @@ TEST(APIntTest, PowerSignedMinValueTo1) { // Test that MaxValue^3 == MaxValue TEST(APIntTest, ZeroToZero) { APInt Zero = APInt::getZero(32); - APInt One = APInt::getZero(32) + 1; + APInt One(32,1); APInt ZeroToZero = APIntOps::pow(Zero, 0); EXPECT_EQ(ZeroToZero, One); } From 7aea8ba4c334d39b7d5b051268cbee0a17956e27 Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Thu, 16 Jan 2025 21:47:00 +0000 Subject: [PATCH 15/16] fmt --- llvm/unittests/ADT/APIntTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index f1aad25d6ec51..3abd3fb1e3445 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -91,7 +91,7 @@ TEST(APIntTest, PowerSignedMinValueTo1) { // Test that MaxValue^3 == MaxValue TEST(APIntTest, ZeroToZero) { APInt Zero = APInt::getZero(32); - APInt One(32,1); + APInt One(32, 1); APInt ZeroToZero = APIntOps::pow(Zero, 0); EXPECT_EQ(ZeroToZero, One); } From f492dfcbef82c79bd61c7b823d020c20ca7ae98a Mon Sep 17 00:00:00 2001 From: ImanHosseini Date: Fri, 17 Jan 2025 11:43:29 +0000 Subject: [PATCH 16/16] V_1024 --- llvm/unittests/ADT/APIntTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 3abd3fb1e3445..b14366eac2185 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -48,7 +48,7 @@ TEST(APIntTest, PowOneTo16) { TEST(APIntTest, PowerTwoTo10) { APInt Two(32, 2); APInt TwoTo20 = APIntOps::pow(Two, 10); - APInt V_1024 = APInt::getZero(32) + 1024; + APInt V_1024(32, 1024); EXPECT_EQ(TwoTo20, V_1024); }