Skip to content

Commit b9e4679

Browse files
authored
[DAG] canCreateUndefOrPoison - add handling for ADD/SUB/MUL overflow nodes (#146322)
Neither the arithmetic value or overflow result can create undef/poison from regular operands values. We have complete test coverage for all ADDO/SUBO nodes, 32-bit codegen handles the _CARRY variants but until #145939 lands AND DAGCombiner::visitFREEZE handles multiple results we can't see any codegen change. Pulled out of #145939
1 parent eb1a80b commit b9e4679

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5557,6 +5557,23 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
55575557
case ISD::SPLAT_VECTOR:
55585558
return false;
55595559

5560+
case ISD::ADDC:
5561+
case ISD::SUBC:
5562+
case ISD::ADDE:
5563+
case ISD::SUBE:
5564+
case ISD::SADDO:
5565+
case ISD::SSUBO:
5566+
case ISD::SMULO:
5567+
case ISD::SADDO_CARRY:
5568+
case ISD::SSUBO_CARRY:
5569+
case ISD::UADDO:
5570+
case ISD::USUBO:
5571+
case ISD::UMULO:
5572+
case ISD::UADDO_CARRY:
5573+
case ISD::USUBO_CARRY:
5574+
// No poison on result or overflow flags.
5575+
return false;
5576+
55605577
case ISD::SELECT_CC:
55615578
case ISD::SETCC: {
55625579
// Integer setcc cannot create undef or poison.

llvm/test/CodeGen/X86/freeze-binary.ll

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,9 @@ define i32 @freeze_saddo(i32 %a0, i32 %a1, i8 %a2, i8 %a3) nounwind {
814814
;
815815
; X64-LABEL: freeze_saddo:
816816
; X64: # %bb.0:
817-
; X64-NEXT: # kill: def $esi killed $esi def $rsi
818-
; X64-NEXT: # kill: def $edi killed $edi def $rdi
817+
; X64-NEXT: movl %edi, %eax
819818
; X64-NEXT: addb %cl, %dl
820-
; X64-NEXT: adcl $0, %edi
821-
; X64-NEXT: leal (%rdi,%rsi), %eax
819+
; X64-NEXT: adcl %esi, %eax
822820
; X64-NEXT: retq
823821
%b = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a2, i8 %a3)
824822
%b.o = extractvalue {i8, i1} %b, 1
@@ -844,11 +842,9 @@ define i32 @freeze_uaddo(i32 %a0, i32 %a1, i8 %a2, i8 %a3) nounwind {
844842
;
845843
; X64-LABEL: freeze_uaddo:
846844
; X64: # %bb.0:
847-
; X64-NEXT: # kill: def $esi killed $esi def $rsi
848-
; X64-NEXT: # kill: def $edi killed $edi def $rdi
845+
; X64-NEXT: movl %edi, %eax
849846
; X64-NEXT: addb %cl, %dl
850-
; X64-NEXT: adcl $0, %edi
851-
; X64-NEXT: leal (%rdi,%rsi), %eax
847+
; X64-NEXT: adcl %esi, %eax
852848
; X64-NEXT: retq
853849
%b = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a2, i8 %a3)
854850
%b.o = extractvalue {i8, i1} %b, 1
@@ -878,11 +874,8 @@ define i32 @freeze_ssubo(i32 %a0, i32 %a1, i8 %a2, i8 %a3) nounwind {
878874
; X64-LABEL: freeze_ssubo:
879875
; X64: # %bb.0:
880876
; X64-NEXT: movl %edi, %eax
881-
; X64-NEXT: xorl %edi, %edi
882877
; X64-NEXT: addb %cl, %dl
883-
; X64-NEXT: setb %dil
884-
; X64-NEXT: andl $1, %edi
885-
; X64-NEXT: subl %edi, %eax
878+
; X64-NEXT: sbbl $0, %eax
886879
; X64-NEXT: subl %esi, %eax
887880
; X64-NEXT: retq
888881
%b = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a2, i8 %a3)
@@ -913,11 +906,8 @@ define i32 @freeze_usubo(i32 %a0, i32 %a1, i8 %a2, i8 %a3) nounwind {
913906
; X64-LABEL: freeze_usubo:
914907
; X64: # %bb.0:
915908
; X64-NEXT: movl %edi, %eax
916-
; X64-NEXT: xorl %edi, %edi
917909
; X64-NEXT: addb %cl, %dl
918-
; X64-NEXT: setb %dil
919-
; X64-NEXT: andl $1, %edi
920-
; X64-NEXT: subl %edi, %eax
910+
; X64-NEXT: sbbl $0, %eax
921911
; X64-NEXT: subl %esi, %eax
922912
; X64-NEXT: retq
923913
%b = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a2, i8 %a3)

0 commit comments

Comments
 (0)