forked from OSchip/llvm-project
[InstCombine] fix use check when canonicalizing abs/nabs
We were checking for extra uses of the negated operand even if we were not going to create it as part of this canonicalization. This was showing up as a regression when we limit EarlyCSE as proposed in D74285.
This commit is contained in:
parent
93073e52b1
commit
62ce7e650a
|
@ -1073,8 +1073,9 @@ static Instruction *canonicalizeAbsNabs(SelectInst &Sel, ICmpInst &Cmp,
|
|||
if (CmpCanonicalized && RHSCanonicalized)
|
||||
return nullptr;
|
||||
|
||||
// If RHS is used by other instructions except compare and select, don't
|
||||
// canonicalize it to not increase the instruction count.
|
||||
// If RHS is not canonical but is used by other instructions, don't
|
||||
// canonicalize it and potentially increase the instruction count.
|
||||
if (!RHSCanonicalized)
|
||||
if (!(RHS->hasOneUse() || (RHS->hasNUses(2) && CmpUsesNegatedOp)))
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -573,8 +573,8 @@ define i8 @abs_swapped(i8 %a) {
|
|||
; CHECK-LABEL: @abs_swapped(
|
||||
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
|
||||
; CHECK-NEXT: call void @extra_use(i8 [[NEG]])
|
||||
; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], 0
|
||||
; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]]
|
||||
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0
|
||||
; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[NEG]], i8 [[A]]
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
;
|
||||
%neg = sub i8 0, %a
|
||||
|
@ -588,8 +588,8 @@ define i8 @nabs_swapped(i8 %a) {
|
|||
; CHECK-LABEL: @nabs_swapped(
|
||||
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
|
||||
; CHECK-NEXT: call void @extra_use(i8 [[NEG]])
|
||||
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], 0
|
||||
; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]]
|
||||
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[A]], 0
|
||||
; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[A]], i8 [[NEG]]
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
;
|
||||
%neg = sub i8 0, %a
|
||||
|
@ -603,8 +603,8 @@ define i8 @abs_different_constants(i8 %a) {
|
|||
; CHECK-LABEL: @abs_different_constants(
|
||||
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
|
||||
; CHECK-NEXT: call void @extra_use(i8 [[NEG]])
|
||||
; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], -1
|
||||
; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]]
|
||||
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0
|
||||
; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[NEG]], i8 [[A]]
|
||||
; CHECK-NEXT: ret i8 [[M1]]
|
||||
;
|
||||
%neg = sub i8 0, %a
|
||||
|
@ -618,8 +618,8 @@ define i8 @nabs_different_constants(i8 %a) {
|
|||
; CHECK-LABEL: @nabs_different_constants(
|
||||
; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
|
||||
; CHECK-NEXT: call void @extra_use(i8 [[NEG]])
|
||||
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i8 [[A]], -1
|
||||
; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[NEG]], i8 [[A]]
|
||||
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[A]], 0
|
||||
; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMP2]], i8 [[A]], i8 [[NEG]]
|
||||
; CHECK-NEXT: ret i8 [[M2]]
|
||||
;
|
||||
%neg = sub i8 0, %a
|
||||
|
|
Loading…
Reference in New Issue