Skip to content

Commit 740758a

Browse files
authored
[X86][APX] Combine xor .., -1 into Cload/Cstore conditions (#151457)
Remove redundant NOT instruction: https://godbolt.org/z/jM89ejnsh
1 parent 1acfa18 commit 740758a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58071,12 +58071,24 @@ static SDValue combineX86CloadCstore(SDNode *N, SelectionDAG &DAG) {
5807158071
Ops[3] = Op1.getOperand(0);
5807258072
Ops[4] = Op1.getOperand(1);
5807358073
} else if (Op1.getOpcode() == ISD::AND && Sub.getValue(0).use_empty()) {
58074+
SDValue Src = Op1;
58075+
SDValue Op10 = Op1.getOperand(0);
58076+
if (Op10.getOpcode() == ISD::XOR && isAllOnesConstant(Op10.getOperand(1))) {
58077+
// res, flags2 = sub 0, (and (xor X, -1), Y)
58078+
// cload/cstore ..., cond_ne, flag2
58079+
// ->
58080+
// res, flags2 = sub 0, (and X, Y)
58081+
// cload/cstore ..., cond_e, flag2
58082+
Src = DAG.getNode(ISD::AND, DL, Op1.getValueType(), Op10.getOperand(0),
58083+
Op1.getOperand(1));
58084+
Ops[3] = DAG.getTargetConstant(X86::COND_E, DL, MVT::i8);
58085+
}
5807458086
// res, flags2 = sub 0, (and X, Y)
58075-
// cload/cstore ..., cond_ne, flag2
58087+
// cload/cstore ..., cc, flag2
5807658088
// ->
5807758089
// res, flags2 = cmp (and X, Y), 0
58078-
// cload/cstore ..., cond_ne, flag2
58079-
Ops[4] = DAG.getNode(X86ISD::CMP, DL, MVT::i32, Op1, Sub.getOperand(0));
58090+
// cload/cstore ..., cc, flag2
58091+
Ops[4] = DAG.getNode(X86ISD::CMP, DL, MVT::i32, Src, Sub.getOperand(0));
5808058092
} else {
5808158093
return SDValue();
5808258094
}

llvm/test/CodeGen/X86/apx/cf.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,17 @@ next:
215215
store <1 x i32> %2, ptr %p, align 4
216216
ret void
217217
}
218+
219+
define void @xor_cond(ptr %p, i1 %cond) {
220+
; CHECK-LABEL: xor_cond:
221+
; CHECK: # %bb.0: # %entry
222+
; CHECK-NEXT: xorl %eax, %eax
223+
; CHECK-NEXT: testb $1, %sil
224+
; CHECK-NEXT: cfcmovel %eax, (%rdi)
225+
; CHECK-NEXT: retq
226+
entry:
227+
%0 = xor i1 %cond, true
228+
%1 = insertelement <1 x i1> zeroinitializer, i1 %0, i64 0
229+
call void @llvm.masked.store.v1i32.p0(<1 x i32> zeroinitializer, ptr %p, i32 1, <1 x i1> %1)
230+
ret void
231+
}

0 commit comments

Comments
 (0)