-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Only check assertions that were meant to apply to the normal case of non-splat vector SREM expansion when we aren't hitting the special case. #86238
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
of non-splat vector SREM expansion when we aren't hitting the special case. Fixes llvm#84830 Introduced in llvm#82706
@llvm/pr-subscribers-llvm-selectiondag Author: Owen Anderson (resistor) ChangesFixes #84830 Full diff: https://github.com/llvm/llvm-project/pull/86238.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index da29b1d5b312f8..8be03b66e155f6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -6916,6 +6916,11 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
// Q = floor((2 * A) / (2^K))
APInt Q = (2 * A).udiv(APInt::getOneBitSet(W, K));
+ assert(APInt::getAllOnes(SVT.getSizeInBits()).ugt(A) &&
+ "We are expecting that A is always less than all-ones for SVT");
+ assert(APInt::getAllOnes(ShSVT.getSizeInBits()).ugt(K) &&
+ "We are expecting that K is always less than all-ones for ShSVT");
+
// If D was a power of two, apply the alternate constant derivation.
if (D0.isOne()) {
// A = 2^(W-1)
@@ -6924,11 +6929,6 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
Q = APInt::getAllOnes(W - K).zext(W);
}
- assert(APInt::getAllOnes(SVT.getSizeInBits()).ugt(A) &&
- "We are expecting that A is always less than all-ones for SVT");
- assert(APInt::getAllOnes(ShSVT.getSizeInBits()).ugt(K) &&
- "We are expecting that K is always less than all-ones for ShSVT");
-
// If the divisor is 1 the result can be constant-folded. Likewise, we
// don't care about INT_MIN lanes, those can be set to undef if appropriate.
if (D.isOne()) {
diff --git a/llvm/test/CodeGen/AArch64/srem-vec-crash.ll b/llvm/test/CodeGen/AArch64/srem-vec-crash.ll
new file mode 100644
index 00000000000000..3b8a1c83b2f697
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/srem-vec-crash.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+;RUN: llc -mtriple=aarch64-unknown-unknown < %s | FileCheck %s
+
+define i32 @f(i1 %0) {
+; CHECK-LABEL: f:
+; CHECK: // %bb.0:
+; CHECK-NEXT: mov w0, #1 // =0x1
+; CHECK-NEXT: ret
+ %new0 = srem i1 %0, true
+ %last = zext i1 %new0 to i32
+ %2 = icmp ne i32 %last, 0
+ %3 = select i1 %2, i32 0, i32 1
+ ret i32 %3
+}
|
@llvm/pr-subscribers-backend-aarch64 Author: Owen Anderson (resistor) ChangesFixes #84830 Full diff: https://github.com/llvm/llvm-project/pull/86238.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index da29b1d5b312f8..8be03b66e155f6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -6916,6 +6916,11 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
// Q = floor((2 * A) / (2^K))
APInt Q = (2 * A).udiv(APInt::getOneBitSet(W, K));
+ assert(APInt::getAllOnes(SVT.getSizeInBits()).ugt(A) &&
+ "We are expecting that A is always less than all-ones for SVT");
+ assert(APInt::getAllOnes(ShSVT.getSizeInBits()).ugt(K) &&
+ "We are expecting that K is always less than all-ones for ShSVT");
+
// If D was a power of two, apply the alternate constant derivation.
if (D0.isOne()) {
// A = 2^(W-1)
@@ -6924,11 +6929,6 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
Q = APInt::getAllOnes(W - K).zext(W);
}
- assert(APInt::getAllOnes(SVT.getSizeInBits()).ugt(A) &&
- "We are expecting that A is always less than all-ones for SVT");
- assert(APInt::getAllOnes(ShSVT.getSizeInBits()).ugt(K) &&
- "We are expecting that K is always less than all-ones for ShSVT");
-
// If the divisor is 1 the result can be constant-folded. Likewise, we
// don't care about INT_MIN lanes, those can be set to undef if appropriate.
if (D.isOne()) {
diff --git a/llvm/test/CodeGen/AArch64/srem-vec-crash.ll b/llvm/test/CodeGen/AArch64/srem-vec-crash.ll
new file mode 100644
index 00000000000000..3b8a1c83b2f697
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/srem-vec-crash.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+;RUN: llc -mtriple=aarch64-unknown-unknown < %s | FileCheck %s
+
+define i32 @f(i1 %0) {
+; CHECK-LABEL: f:
+; CHECK: // %bb.0:
+; CHECK-NEXT: mov w0, #1 // =0x1
+; CHECK-NEXT: ret
+ %new0 = srem i1 %0, true
+ %last = zext i1 %new0 to i32
+ %2 = icmp ne i32 %last, 0
+ %3 = select i1 %2, i32 0, i32 1
+ ret i32 %3
+}
|
arsenm
approved these changes
Mar 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #84830
Introduced in #82706