Skip to content

Commit 42c5f6c

Browse files
uweigandgithub-actions[bot]
authored andcommitted
Automerge: [SystemZ] Fix ICE with i128->i64 uaddo carry chain
We can only optimize a uaddo_carry via specialized instruction if the carry was produced by another uaddo(_carry) instruction; there is already a check for that. However, i128 uaddo(_carry) use a completely different mechanism; they indicate carry in a vector register instead of the CC flag. Thus, we must also check that we don't mix those two - that check has been missing. Fixes: llvm/llvm-project#124001
2 parents 13fc30c + 6d5697f commit 42c5f6c

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4708,15 +4708,19 @@ SDValue SystemZTargetLowering::lowerXALUO(SDValue Op,
47084708
}
47094709

47104710
static bool isAddCarryChain(SDValue Carry) {
4711-
while (Carry.getOpcode() == ISD::UADDO_CARRY)
4711+
while (Carry.getOpcode() == ISD::UADDO_CARRY &&
4712+
Carry->getValueType(0) != MVT::i128)
47124713
Carry = Carry.getOperand(2);
4713-
return Carry.getOpcode() == ISD::UADDO;
4714+
return Carry.getOpcode() == ISD::UADDO &&
4715+
Carry->getValueType(0) != MVT::i128;
47144716
}
47154717

47164718
static bool isSubBorrowChain(SDValue Carry) {
4717-
while (Carry.getOpcode() == ISD::USUBO_CARRY)
4719+
while (Carry.getOpcode() == ISD::USUBO_CARRY &&
4720+
Carry->getValueType(0) != MVT::i128)
47184721
Carry = Carry.getOperand(2);
4719-
return Carry.getOpcode() == ISD::USUBO;
4722+
return Carry.getOpcode() == ISD::USUBO &&
4723+
Carry->getValueType(0) != MVT::i128;
47204724
}
47214725

47224726
// Lower UADDO_CARRY/USUBO_CARRY nodes.

llvm/test/CodeGen/SystemZ/pr124001.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 | FileCheck %s
3+
4+
define i64 @test(i128 %in) {
5+
; CHECK-LABEL: test:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: larl %r1, .LCPI0_0
8+
; CHECK-NEXT: vl %v0, 0(%r2), 3
9+
; CHECK-NEXT: vl %v1, 0(%r1), 3
10+
; CHECK-NEXT: vaccq %v0, %v0, %v1
11+
; CHECK-NEXT: vlgvg %r1, %v0, 1
12+
; CHECK-NEXT: la %r2, 1(%r1)
13+
; CHECK-NEXT: br %r14
14+
%1 = tail call { i128, i1 } @llvm.uadd.with.overflow.i128(i128 %in, i128 1)
15+
%2 = extractvalue { i128, i1 } %1, 1
16+
%3 = zext i1 %2 to i64
17+
%4 = add i64 %3, 1
18+
ret i64 %4
19+
}
20+
21+
declare { i128, i1 } @llvm.uadd.with.overflow.i128(i128, i128) #0
22+
23+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)