llvm.org GIT mirror llvm / 95c68f1
[SystemZ] Fix addcarry of usubo (PR42512) Only custom lower uaddo+addcarry or usubo+subcarry chains and leave mixtures like usubo+addcarry or uaddo+subcarry to the generic legalizer. Otherwise we run into issues because SystemZ uses different CC values for carries and borrows. Fixes https://bugs.llvm.org/show_bug.cgi?id=42512. Differential Revision: https://reviews.llvm.org/D64213 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365242 91177308-0d34-0410-b5e6-96231b3b80d8 Nikita Popov 4 months ago
2 changed file(s) with 29 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
34483448 switch (Op.getOpcode()) {
34493449 default: llvm_unreachable("Unknown instruction!");
34503450 case ISD::ADDCARRY:
3451 if (Carry.getOpcode() != ISD::UADDO && Carry.getOpcode() != ISD::ADDCARRY)
3452 return SDValue();
3453
34513454 BaseOp = SystemZISD::ADDCARRY;
34523455 CCValid = SystemZ::CCMASK_LOGICAL;
34533456 CCMask = SystemZ::CCMASK_LOGICAL_CARRY;
34543457 break;
34553458 case ISD::SUBCARRY:
3459 if (Carry.getOpcode() != ISD::USUBO && Carry.getOpcode() != ISD::SUBCARRY)
3460 return SDValue();
3461
34563462 BaseOp = SystemZISD::SUBCARRY;
34573463 CCValid = SystemZ::CCMASK_LOGICAL;
34583464 CCMask = SystemZ::CCMASK_LOGICAL_BORROW;
0 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
1 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
2
3 define i8 @test(i8 %x) {
4 ; CHECK-LABEL: test:
5 ; CHECK: # %bb.0:
6 ; CHECK-NEXT: slgfi %r0, 1
7 ; CHECK-NEXT: ipm %r0
8 ; CHECK-NEXT: afi %r0, -536870912
9 ; CHECK-NEXT: srl %r0, 31
10 ; CHECK-NEXT: ar %r2, %r0
11 ; CHECK-NEXT: br %r14
12 %usubo = tail call { i64, i1 } @llvm.usub.with.overflow.i64(i64 undef, i64 1)
13 %ov = extractvalue { i64, i1 } %usubo, 1
14 %ovext = zext i1 %ov to i8
15 %ret = add i8 %x, %ovext
16 ret i8 %ret
17 }
18
19 ; Function Attrs: nounwind readnone speculatable
20 declare { i64, i1 } @llvm.usub.with.overflow.i64(i64, i64) #0
21
22 attributes #0 = { nounwind readnone speculatable }