-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reapply [APInt] Enable APInt ctor assertion by default #114539
Conversation
This enables the assertion introduced in llvm#106524, which checks that the value passed to the constructor is indeed a valid N-bit signed or unsigned integer. Places that previously violated the assertion were updated in advance, e.g. in llvm#80309. It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true. ----- The buildbot failures from the previous attempt should be fixed by a18dd29 and e2074c6.
@llvm/pr-subscribers-llvm-adt Author: Nikita Popov (nikic) ChangesThis enables the assertion introduced in Places that previously violated the assertion were updated in advance, e.g. in #80309. It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true. The buildbot failures from the previous attempt should be fixed by a18dd29 and Full diff: https://github.com/llvm/llvm-project/pull/114539.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 63a138527b32e1..953b2a27b71526 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -109,7 +109,7 @@ class [[nodiscard]] APInt {
/// \param implicitTrunc allow implicit truncation of non-zero/sign bits of
/// val beyond the range of numBits
APInt(unsigned numBits, uint64_t val, bool isSigned = false,
- bool implicitTrunc = true)
+ bool implicitTrunc = false)
: BitWidth(numBits) {
if (!implicitTrunc) {
if (isSigned) {
|
When trying to create a const inst from a 32 bit signed value, we don't want to sign-extend it to 64 bits, as the resulting value won't actually fit in an `i32` if it was negative. This fixes crashes in the following two tests after the APInt constructor asserts were enabled in llvm#114539: ``` Failed Tests (2): LLVM :: CodeGen/SPIRV/transcoding/RelationalOperators.ll LLVM :: CodeGen/SPIRV/uitofp-with-bool.ll ```
I am seeing an assertion failure while building the Linux kernel after this change. int am33xx_check_features___trans_tmp_5;
int omap_rev();
void __attribute__((__cold__)) am33xx_check_features() {
am33xx_check_features___trans_tmp_5 = omap_rev() >> 20 == 363;
}
If a separate issue would be helpful, I am happy to file one. |
This enables the assertion introduced in llvm#106524, which checks that the value passed to the constructor is indeed a valid N-bit signed or unsigned integer. Places that previously violated the assertion were updated in advance, e.g. in llvm#80309. It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true. ----- The buildbot failures from the previous attempt should be fixed by a18dd29 and e2074c6.
This enables the assertion introduced in llvm#106524, which checks that the value passed to the constructor is indeed a valid N-bit signed or unsigned integer. Places that previously violated the assertion were updated in advance, e.g. in llvm#80309. It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true. ----- The buildbot failures from the previous attempt should be fixed by a18dd29 and e2074c6.
This enables the assertion introduced in llvm#106524, which checks that the value passed to the constructor is indeed a valid N-bit signed or unsigned integer. Places that previously violated the assertion were updated in advance, e.g. in llvm#80309. It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true. ----- The buildbot failures from the previous attempt should be fixed by a18dd29 and e2074c6.
@nathanchance Thanks for the report! Here's a minimized test case: ; RUN: opt -S -passes=consthoist < %s
target triple = "armv4t-unknown-linux-gnueabi"
define i1 @test(i32 %arg) optsize {
entry:
%shr.mask = and i32 %arg, -1048576
%cmp = icmp eq i32 %shr.mask, 380633088
ret i1 %cmp
} |
The result here may require truncation. Fix this by removing the calculateOffsetDiff() helper entirely. As far as I can tell, this code does not actually have to deal with different bitwidths. findBaseConstants() will produce ranges of constants with equal types, which is what maximizeConstantsInRange() will then work on. Fixes assertion reported at: #114539 (comment)
@nathanchance I've applied a fix in 8851ea6. Let me know if you see further issues. |
When trying to create a const inst from a 32 bit signed value, we don't want to sign-extend it to 64 bits, as the resulting value won't actually fit in an `i32` if it was negative. This fixes crashes in the following two tests after the APInt constructor asserts were enabled in #114539: ``` Failed Tests (2): LLVM :: CodeGen/SPIRV/transcoding/RelationalOperators.ll LLVM :: CodeGen/SPIRV/uitofp-with-bool.ll ```
Hi @nikic , Another crash like this:
|
@mikaelholmen Thanks, should be fixed by 46ccefb. |
The result here may require truncation. Fix this by removing the calculateOffsetDiff() helper entirely. As far as I can tell, this code does not actually have to deal with different bitwidths. findBaseConstants() will produce ranges of constants with equal types, which is what maximizeConstantsInRange() will then work on. Fixes assertion reported at: llvm#114539 (comment)
…4630) When trying to create a const inst from a 32 bit signed value, we don't want to sign-extend it to 64 bits, as the resulting value won't actually fit in an `i32` if it was negative. This fixes crashes in the following two tests after the APInt constructor asserts were enabled in llvm#114539: ``` Failed Tests (2): LLVM :: CodeGen/SPIRV/transcoding/RelationalOperators.ll LLVM :: CodeGen/SPIRV/uitofp-with-bool.ll ```
…stant. NFC (llvm#114336) This assert is also present inside the APInt constructor after llvm#114539.
Another one here:
|
The (extended) bit width might not fit into the (non-extended) type, resulting in an incorrect truncation of the compared value. Fix this by using m_SpecificInt(), which is both simpler and handles this correctly. Fixes the assertion failure reported in: #114539 (comment)
@mikaelholmen Thanks, should be fixed by abac5be. |
Yep, thanks! |
The (extended) bit width might not fit into the (non-extended) type, resulting in an incorrect truncation of the compared value. Fix this by using m_SpecificInt(), which is both simpler and handles this correctly. Fixes the assertion failure reported in: llvm#114539 (comment)
…9808c3cce Local branch amd-gfx 96d9808 Revert "Reapply [APInt] Enable APInt ctor assertion by default (llvm#114539)" Remote branch main 2de3d00 [mlir][tosa] Fix a crash in `PadOp::fold` (llvm#114921)
Hi @nikic , Another failure like this:
It fails on this in InstCombinerImpl::foldICmpAddConstant:
|
If the bitwidth is 2 and we add two 1s, the result may overflow. This is fine in terms of correctness, but triggers the APInt ctor assertion. Fix this by performing the calculation directly on APInts. Fixes the issue reported in: #114539 (comment)
@mikaelholmen Thanks, should be fixed by 63d4e0f. |
Yep, thanks! |
If the bitwidth is 2 and we add two 1s, the result may overflow. This is fine in terms of correctness, but triggers the APInt ctor assertion. Fix this by performing the calculation directly on APInts. Fixes the issue reported in: llvm/llvm-project#114539 (comment)
This enables the assertion introduced in #106524, which checks that the value passed to the constructor is indeed a valid N-bit signed or unsigned integer.
Places that previously violated the assertion were updated in advance, e.g. in #80309.
It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true.
The buildbot failures from the previous attempt should be fixed by a18dd29 and
e2074c6.