Skip to content

Commit 9d11ba7

Browse files
committed
[Hexagon] Explicitly truncate constant in UAddSubO
After llvm#117558 landed, this code would assert "Value is not an N-bit unsigned value" in getConstant(), from a test case in zig. Co-authored-by: Craig Topper <[email protected]> Fixes llvm#127296
1 parent 256145b commit 9d11ba7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3273,7 +3273,7 @@ HexagonTargetLowering::LowerUAddSubO(SDValue Op, SelectionDAG &DAG) const {
32733273
if (Opc == ISD::USUBO) {
32743274
SDValue Op = DAG.getNode(ISD::SUB, dl, VTs.VTs[0], {X, Y});
32753275
SDValue Ov = DAG.getSetCC(dl, MVT::i1, Op,
3276-
DAG.getConstant(-1, dl, ty(Op)), ISD::SETEQ);
3276+
DAG.getAllOnesConstant(dl, ty(Op)), ISD::SETEQ);
32773277
return DAG.getMergeValues({Op, Ov}, dl);
32783278
}
32793279
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llc -mtriple=hexagon -O0 < %s | FileCheck %s
2+
3+
; CHECK: r0 = add(r0,#-1)
4+
5+
define fastcc void @os.linux.tls.initStatic(i32 %x) {
6+
%1 = call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %x, i32 1)
7+
br label %2
8+
9+
2: ; preds = %0
10+
%3 = extractvalue { i32, i1 } %1, 0
11+
ret void
12+
}
13+
14+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
15+
declare { i32, i1 } @llvm.usub.with.overflow.i32(i32, i32) #0
16+
17+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
18+

0 commit comments

Comments
 (0)