Skip to content

Commit 82a1bff

Browse files
authored
[SelectionDAG] Do not crash on large integers in CheckInteger (#75787)
The CheckInteger routine called from TableGen-generated selection logic uses getSExtValue - which will abort if the underlying APInt does not fit into an int64_t. This case is now triggered by the SystemZ back-end since i128 is a legal type on certain machines. While we do not have any regular instructions that take 128-bit immediates (like most other platforms), there are patterns in the .td files that recognize an i128 "xor ..., -1" as a "not". These patterns cause code to be generated that calls the CheckInteger routine on some i128-valued integer, which may trigger the assert. Fix by using trySExtValue instead. Fixes #75710
1 parent 74cf525 commit 82a1bff

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,7 @@ CheckInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
27862786
Val = decodeSignRotatedValue(Val);
27872787

27882788
ConstantSDNode *C = dyn_cast<ConstantSDNode>(N);
2789-
return C && C->getSExtValue() == Val;
2789+
return C && C->getAPIntValue().trySExtValue() == Val;
27902790
}
27912791

27922792
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool

llvm/test/CodeGen/SystemZ/xor-09.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ define i128 @f1(i128 %a, i128 %b) {
1515
%res = xor i128 %a, %b
1616
ret i128 %res
1717
}
18+
19+
; Verify that xor with a large constant does not crash.
20+
define i128 @f2(i128 %x) {
21+
; CHECK-LABEL: f2:
22+
; CHECK: # %bb.0:
23+
; CHECK-NEXT: larl %r1, .LCPI1_0
24+
; CHECK-NEXT: vl %v0, 0(%r3), 3
25+
; CHECK-NEXT: vl %v1, 0(%r1), 3
26+
; CHECK-NEXT: vx %v0, %v0, %v1
27+
; CHECK-NEXT: vst %v0, 0(%r2), 3
28+
; CHECK-NEXT: br %r14
29+
%res = xor i128 %x, 17440380254424117642
30+
ret i128 %res
31+
}

0 commit comments

Comments
 (0)