-
Notifications
You must be signed in to change notification settings - Fork 14k
[LoongArch] Fix out-of-range assert in DAG constant getting #141586
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-backend-loongarch Author: hev (heiher) ChangesFixes #141583 Full diff: https://github.com/llvm/llvm-project/pull/141586.diff 2 Files Affected:
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 9f5c94ddea44f..7a9ec9f5e96b3 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -4410,7 +4410,7 @@ static SDValue performORCombine(SDNode *N, SelectionDAG &DAG,
LLVM_DEBUG(dbgs() << "Perform OR combine: match pattern 5\n");
return DAG.getNode(
LoongArchISD::BSTRINS, DL, ValTy, N0.getOperand(0),
- DAG.getConstant(CN1->getSExtValue() >> MaskIdx0, DL, ValTy),
+ DAG.getSignedConstant(CN1->getSExtValue() >> MaskIdx0, DL, ValTy),
DAG.getConstant(ValBits == 32 ? (MaskIdx0 + (MaskLen0 & 31) - 1)
: (MaskIdx0 + MaskLen0 - 1),
DL, GRLenVT),
diff --git a/llvm/test/CodeGen/LoongArch/bstrins_w.ll b/llvm/test/CodeGen/LoongArch/bstrins_w.ll
index c59f15bd64112..0fea0470394d2 100644
--- a/llvm/test/CodeGen/LoongArch/bstrins_w.ll
+++ b/llvm/test/CodeGen/LoongArch/bstrins_w.ll
@@ -207,6 +207,18 @@ define i32 @pat8(i32 %c) nounwind {
ret i32 %or
}
+define i32 @pat9(i32 %a) {
+; CHECK-LABEL: pat9:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lu12i.w $a1, -8
+; CHECK-NEXT: ori $a1, $a1, 564
+; CHECK-NEXT: bstrins.w $a0, $a1, 31, 16
+; CHECK-NEXT: ret
+ %and = and i32 %a, 65535 ; 0x0000ffff
+ %or = or i32 %and, -2110521344 ; 0x82340000
+ ret i32 %or
+}
+
;; Test that bstrins.w is not generated because constant OR operand
;; doesn't fit into bits cleared by constant AND operand.
define i32 @no_bstrins_w(i32 %a) nounwind {
|
@@ -4410,7 +4410,7 @@ static SDValue performORCombine(SDNode *N, SelectionDAG &DAG, | |||
LLVM_DEBUG(dbgs() << "Perform OR combine: match pattern 5\n"); | |||
return DAG.getNode( | |||
LoongArchISD::BSTRINS, DL, ValTy, N0.getOperand(0), | |||
DAG.getConstant(CN1->getSExtValue() >> MaskIdx0, DL, ValTy), | |||
DAG.getSignedConstant(CN1->getSExtValue() >> MaskIdx0, DL, ValTy), |
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.
Do other calls to DAG.getConstant()
have the same issue?
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.
Perhaps. I haven't found any others so far, but if I do, I might fix them in this PR or in a follow-up.
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.
I came across a few more spots that might be risky, based on the data types and value ranges of getConstant()
and getTargetConstant()
. I’ll include defensive fixes in this PR, but given the low risk and similarity of the cases, I’m not planning to add separate tests for each one.
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.
RV similar fix: #125903
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
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/141/builds/9066 Here is the relevant piece of the build log for the reference
|
Fixes #141583