-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[DAG] ComputeNumSignBits - ISD::EXTRACT_ELEMENT needs to return at least 1 #155455
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
Conversation
|
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-backend-amdgpu Author: Miguel Saldivar (Saldivarcher) ChangesIf the value for This is a fix for #155452. Full diff: https://github.com/llvm/llvm-project/pull/155455.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 3672a91e33a30..078825f2a9a22 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5127,7 +5127,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
// If the sign portion ends in our element the subtraction gives correct
// result. Otherwise it gives either negative or > bitwidth result
- return std::clamp(KnownSign - rIndex * BitWidth, 0, BitWidth);
+ return std::clamp(KnownSign - rIndex * BitWidth, 1, BitWidth);
}
case ISD::INSERT_VECTOR_ELT: {
if (VT.isScalableVector())
diff --git a/llvm/test/CodeGen/AMDGPU/pr155452.ll b/llvm/test/CodeGen/AMDGPU/pr155452.ll
new file mode 100644
index 0000000000000..f4be1b4922162
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/pr155452.ll
@@ -0,0 +1,22 @@
+; RUN: llc %s -march=amdgcn -o - | FileCheck %s
+
+target triple = "amdgcn-amd-amdhsa"
+
+define amdgpu_kernel void @my_kernel(i64 %foo, i32 %bar) {
+entry:
+ br label %loop
+
+loop: ; preds = %entry, %loop
+ %i = phi i64 [ 1, %entry ], [ 0, %loop ]
+ %mul = mul i64 %foo, %i
+ %add = add i64 %mul, 1
+ %trunc = trunc i64 %add to i32
+ %div = sdiv i32 %trunc, %bar
+ %sext = sext i32 %div to i64
+ %or = or i64 %add, %sext
+ %inttoptr = inttoptr i64 %or to ptr
+ %addrspacecast = addrspacecast ptr %inttoptr to ptr addrspace(1)
+ %val = load double, ptr addrspace(1) %addrspacecast, align 8
+ store double %val, ptr addrspace(1) null, align 8
+ br label %loop
+}
|
|
Description and/or title should mention the affected opcode. |
a0f4ec9 to
c2d0846
Compare
Thanks for the tip, I didn't know that! Let me know how that looks now. |
topperc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ast 1 When going through the ISD::EXTRACT_ELEMENT case, `KnownSign - rIndex * BitWidth` could produce a negative. When a negative is produced, the lower bound of the `std::clamp` is returned. Change that lower bound to one to avoid potential underflows, because the expectation is that `ComputeNumSignBits` should always return at least 1. Fixes llvm#155452.
c2d0846 to
348a416
Compare
|
@topperc do you think you can merge this for me, please? I don't have commit access. And thanks again for the review! |
When going through the ISD::EXTRACT_ELEMENT case,
KnownSign - rIndex * BitWidthcould produce a negative. When a negative is produced, the lower bound
of the
std::clampis returned. Change that lower bound to one to avoidpotential underflows, because the expectation is that
ComputeNumSignBitsshould always return at least 1.
Fixes #155452.