Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 06ded73

Browse files
committed
[X86] Remove combine that turns X86ISD::LSUB into X86ISD::LADD. Update patterns that depended on this.
If the carry flag is being used, this transformation isn't safe. This does prevent some test cases from using DEC now, but I'll try to look into that separately. Fixes PR35068. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316860 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5fac927 commit 06ded73

File tree

3 files changed

+11
-32
lines changed

3 files changed

+11
-32
lines changed

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36254,26 +36254,6 @@ static SDValue combineVSZext(SDNode *N, SelectionDAG &DAG,
3625436254
return SDValue();
3625536255
}
3625636256

36257-
/// Canonicalize (LSUB p, 1) -> (LADD p, -1).
36258-
static SDValue combineLockSub(SDNode *N, SelectionDAG &DAG,
36259-
const X86Subtarget &Subtarget) {
36260-
SDValue Chain = N->getOperand(0);
36261-
SDValue LHS = N->getOperand(1);
36262-
SDValue RHS = N->getOperand(2);
36263-
MVT VT = RHS.getSimpleValueType();
36264-
SDLoc DL(N);
36265-
36266-
auto *C = dyn_cast<ConstantSDNode>(RHS);
36267-
if (!C || C->getZExtValue() != 1)
36268-
return SDValue();
36269-
36270-
RHS = DAG.getConstant(-1, DL, VT);
36271-
MachineMemOperand *MMO = cast<MemSDNode>(N)->getMemOperand();
36272-
return DAG.getMemIntrinsicNode(X86ISD::LADD, DL,
36273-
DAG.getVTList(MVT::i32, MVT::Other),
36274-
{Chain, LHS, RHS}, VT, MMO);
36275-
}
36276-
3627736257
static SDValue combineTestM(SDNode *N, SelectionDAG &DAG,
3627836258
const X86Subtarget &Subtarget) {
3627936259
SDValue Op0 = N->getOperand(0);
@@ -36592,7 +36572,6 @@ SDValue X86TargetLowering::PerformDAGCombine(SDNode *N,
3659236572
case ISD::FMA: return combineFMA(N, DAG, Subtarget);
3659336573
case ISD::MGATHER:
3659436574
case ISD::MSCATTER: return combineGatherScatter(N, DAG);
36595-
case X86ISD::LSUB: return combineLockSub(N, DAG, Subtarget);
3659636575
case X86ISD::TESTM: return combineTestM(N, DAG, Subtarget);
3659736576
case X86ISD::PCMPEQ:
3659836577
case X86ISD::PCMPGT: return combineVectorCompare(N, DAG, Subtarget);

lib/Target/X86/X86InstrCompiler.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def Int_MemBarrier : I<0, Pseudo, (outs), (ins),
593593
// ImmOpc8 corresponds to the mi8 version of the instruction
594594
// ImmMod corresponds to the instruction format of the mi and mi8 versions
595595
multiclass LOCK_ArithBinOp<bits<8> RegOpc, bits<8> ImmOpc, bits<8> ImmOpc8,
596-
Format ImmMod, SDPatternOperator Op, string mnemonic> {
596+
Format ImmMod, SDNode Op, string mnemonic> {
597597
let Defs = [EFLAGS], mayLoad = 1, mayStore = 1, isCodeGenOnly = 1,
598598
SchedRW = [WriteALULd, WriteRMW] in {
599599

@@ -696,31 +696,31 @@ defm LOCK_AND : LOCK_ArithBinOp<0x20, 0x80, 0x83, MRM4m, X86lock_and, "and">;
696696
defm LOCK_XOR : LOCK_ArithBinOp<0x30, 0x80, 0x83, MRM6m, X86lock_xor, "xor">;
697697

698698
multiclass LOCK_ArithUnOp<bits<8> Opc8, bits<8> Opc, Format Form,
699-
int Increment, string mnemonic> {
699+
SDNode Op, string mnemonic> {
700700
let Defs = [EFLAGS], mayLoad = 1, mayStore = 1, isCodeGenOnly = 1,
701701
SchedRW = [WriteALULd, WriteRMW] in {
702702
def NAME#8m : I<Opc8, Form, (outs), (ins i8mem :$dst),
703703
!strconcat(mnemonic, "{b}\t$dst"),
704-
[(set EFLAGS, (X86lock_add addr:$dst, (i8 Increment)))],
704+
[(set EFLAGS, (Op addr:$dst, (i8 1)))],
705705
IIC_UNARY_MEM>, LOCK;
706706
def NAME#16m : I<Opc, Form, (outs), (ins i16mem:$dst),
707707
!strconcat(mnemonic, "{w}\t$dst"),
708-
[(set EFLAGS, (X86lock_add addr:$dst, (i16 Increment)))],
708+
[(set EFLAGS, (Op addr:$dst, (i16 1)))],
709709
IIC_UNARY_MEM>, OpSize16, LOCK;
710710
def NAME#32m : I<Opc, Form, (outs), (ins i32mem:$dst),
711711
!strconcat(mnemonic, "{l}\t$dst"),
712-
[(set EFLAGS, (X86lock_add addr:$dst, (i32 Increment)))],
712+
[(set EFLAGS, (Op addr:$dst, (i32 1)))],
713713
IIC_UNARY_MEM>, OpSize32, LOCK;
714714
def NAME#64m : RI<Opc, Form, (outs), (ins i64mem:$dst),
715715
!strconcat(mnemonic, "{q}\t$dst"),
716-
[(set EFLAGS, (X86lock_add addr:$dst, (i64 Increment)))],
716+
[(set EFLAGS, (Op addr:$dst, (i64 1)))],
717717
IIC_UNARY_MEM>, LOCK;
718718
}
719719
}
720720

721721
let Predicates = [UseIncDec] in {
722-
defm LOCK_INC : LOCK_ArithUnOp<0xFE, 0xFF, MRM0m, 1, "inc">;
723-
defm LOCK_DEC : LOCK_ArithUnOp<0xFE, 0xFF, MRM1m, -1, "dec">;
722+
defm LOCK_INC : LOCK_ArithUnOp<0xFE, 0xFF, MRM0m, X86lock_add, "inc">;
723+
defm LOCK_DEC : LOCK_ArithUnOp<0xFE, 0xFF, MRM1m, X86lock_sub, "dec">;
724724
}
725725

726726
// Atomic compare and swap.

test/CodeGen/X86/atomic-eflags-reuse.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ entry:
3232
define i32 @test_sub_1_cmov_sle(i64* %p, i32 %a0, i32 %a1) #0 {
3333
; CHECK-LABEL: test_sub_1_cmov_sle:
3434
; CHECK: # BB#0: # %entry
35-
; CHECK-NEXT: lock decq (%rdi)
35+
; CHECK-NEXT: lock addq $-1, (%rdi)
3636
; CHECK-NEXT: cmovgel %edx, %esi
3737
; CHECK-NEXT: movl %esi, %eax
3838
; CHECK-NEXT: retq
@@ -46,7 +46,7 @@ entry:
4646
define i32 @test_sub_1_cmov_sgt(i64* %p, i32 %a0, i32 %a1) #0 {
4747
; CHECK-LABEL: test_sub_1_cmov_sgt:
4848
; CHECK: # BB#0: # %entry
49-
; CHECK-NEXT: lock decq (%rdi)
49+
; CHECK-NEXT: lock addq $-1, (%rdi)
5050
; CHECK-NEXT: cmovll %edx, %esi
5151
; CHECK-NEXT: movl %esi, %eax
5252
; CHECK-NEXT: retq
@@ -76,7 +76,7 @@ entry:
7676
define i8 @test_sub_1_setcc_sgt(i64* %p) #0 {
7777
; CHECK-LABEL: test_sub_1_setcc_sgt:
7878
; CHECK: # BB#0: # %entry
79-
; CHECK-NEXT: lock decq (%rdi)
79+
; CHECK-NEXT: lock addq $-1, (%rdi)
8080
; CHECK-NEXT: setge %al
8181
; CHECK-NEXT: retq
8282
entry:

0 commit comments

Comments
 (0)