Skip to content

Commit 47a1704

Browse files
authored
[SelectionDAG][X86] Use disjoint flag in SelectionDAG::isADDLike. (#76847)
Keep the haveNoCommonBitsSet check because we haven't started inferring the flag yet. I've added tests for two transforms, but these are not the only transforms that use isADDLike.
1 parent 7fbc1de commit 47a1704

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7987,7 +7987,7 @@ SDValue DAGCombiner::visitOR(SDNode *N) {
79877987

79887988
// If OR can be rewritten into ADD, try combines based on ADD.
79897989
if ((!LegalOperations || TLI.isOperationLegal(ISD::ADD, VT)) &&
7990-
DAG.haveNoCommonBitsSet(N0, N1))
7990+
DAG.isADDLike(SDValue(N, 0)))
79917991
if (SDValue Combined = visitADDLike(N))
79927992
return Combined;
79937993

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5088,7 +5088,8 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
50885088
bool SelectionDAG::isADDLike(SDValue Op) const {
50895089
unsigned Opcode = Op.getOpcode();
50905090
if (Opcode == ISD::OR)
5091-
return haveNoCommonBitsSet(Op.getOperand(0), Op.getOperand(1));
5091+
return Op->getFlags().hasDisjoint() ||
5092+
haveNoCommonBitsSet(Op.getOperand(0), Op.getOperand(1));
50925093
if (Opcode == ISD::XOR)
50935094
return isMinSignedConstant(Op.getOperand(1));
50945095
return false;

llvm/test/CodeGen/X86/addsub-constant-folding.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,3 +1141,39 @@ define <4 x i32> @vec_const_sub_const_sub_nonsplat(<4 x i32> %arg) {
11411141
%t1 = sub <4 x i32> <i32 2, i32 3, i32 undef, i32 2>, %t0
11421142
ret <4 x i32> %t1
11431143
}
1144+
1145+
; (x|c1)+c2 where (x|c1) is addlike
1146+
define i32 @add_const_disjoint_or_const(i32 %arg) {
1147+
; X86-LABEL: add_const_disjoint_or_const:
1148+
; X86: # %bb.0:
1149+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1150+
; X86-NEXT: addl $10, %eax
1151+
; X86-NEXT: retl
1152+
;
1153+
; X64-LABEL: add_const_disjoint_or_const:
1154+
; X64: # %bb.0:
1155+
; X64-NEXT: # kill: def $edi killed $edi def $rdi
1156+
; X64-NEXT: leal 10(%rdi), %eax
1157+
; X64-NEXT: retq
1158+
%t0 = or disjoint i32 %arg, 8
1159+
%t1 = add i32 %t0, 2
1160+
ret i32 %t1
1161+
}
1162+
1163+
; (x+c1)|c2 where the outer or is addlike
1164+
define i32 @disjoint_or_const_add_const(i32 %arg) {
1165+
; X86-LABEL: disjoint_or_const_add_const:
1166+
; X86: # %bb.0:
1167+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1168+
; X86-NEXT: addl $10, %eax
1169+
; X86-NEXT: retl
1170+
;
1171+
; X64-LABEL: disjoint_or_const_add_const:
1172+
; X64: # %bb.0:
1173+
; X64-NEXT: # kill: def $edi killed $edi def $rdi
1174+
; X64-NEXT: leal 10(%rdi), %eax
1175+
; X64-NEXT: retq
1176+
%t0 = add i32 %arg, 8
1177+
%t1 = or disjoint i32 %t0, 2
1178+
ret i32 %t1
1179+
}

llvm/test/CodeGen/X86/or-lea.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,23 @@ entry:
825825
%or = or i64 %sub, 549755813889 ; 0x8000000001
826826
ret i64 %or
827827
}
828+
829+
define i32 @or_shift1_disjoint(i32 %x, i32 %y) {
830+
; X86-LABEL: or_shift1_disjoint:
831+
; X86: # %bb.0:
832+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
833+
; X86-NEXT: addl %eax, %eax
834+
; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
835+
; X86-NEXT: retl
836+
;
837+
; X64-LABEL: or_shift1_disjoint:
838+
; X64: # %bb.0:
839+
; X64-NEXT: # kill: def $esi killed $esi def $rsi
840+
; X64-NEXT: # kill: def $edi killed $edi def $rdi
841+
; X64-NEXT: leal (%rsi,%rdi,2), %eax
842+
; X64-NEXT: retq
843+
%shl = shl i32 %x, 1
844+
%or = or disjoint i32 %y, %shl
845+
ret i32 %or
846+
}
847+

0 commit comments

Comments
 (0)