[InstCombine] Fix type of constant in canonicalizeClampLike

As a followup to D108049, one of the constants could now be generated
with an incorrect type, now that the input could be truncated.
This commit is contained in:
David Green 2021-10-30 09:06:21 +01:00
parent 3cfc1757c5
commit 66281baea1
2 changed files with 20 additions and 1 deletions

View File

@ -1353,7 +1353,7 @@ static Value *canonicalizeClampLike(SelectInst &Sel0, ICmpInst &Cmp0,
// it should either be the X itself, or an addition of some constant to X.
Constant *C1;
if (Cmp00 == X)
C1 = ConstantInt::getNullValue(Sel0.getType());
C1 = ConstantInt::getNullValue(X->getType());
else if (!match(Cmp00,
m_Add(m_Specific(X),
m_CombineAnd(m_AnyIntegralConstant(), m_Constant(C1)))))

View File

@ -613,3 +613,22 @@ define <2 x i8> @C0zeroVu(<2 x i8> %X, <2 x i8> %y, <2 x i8> %z) {
%r = select <2 x i1> %cmp, <2 x i8> %X, <2 x i8> %f
ret <2 x i8> %r
}
define i8 @f(i32 %value, i8 %call.i) {
; CHECK-LABEL: @f(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[VALUE:%.*]], 0
; CHECK-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], i8 [[CALL_I:%.*]], i8 0
; CHECK-NEXT: [[CMP_I_I:%.*]] = icmp ult i32 [[VALUE]], 256
; CHECK-NEXT: [[CONV4:%.*]] = trunc i32 [[VALUE]] to i8
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP_I_I]], i8 [[CONV4]], i8 [[COND_I]]
; CHECK-NEXT: ret i8 [[COND]]
;
entry:
%cmp.i = icmp slt i32 %value, 0
%cond.i = select i1 %cmp.i, i8 %call.i, i8 0
%cmp.i.i = icmp ult i32 %value, 256
%conv4 = trunc i32 %value to i8
%cond = select i1 %cmp.i.i, i8 %conv4, i8 %cond.i
ret i8 %cond
}