[InstCombine] Fold abs intrinsic eq zero

Following the same transform for the select version of abs.
This commit is contained in:
Nikita Popov 2020-09-05 15:10:09 +02:00
parent 0df23d0dc6
commit ecd979f4bb
2 changed files with 9 additions and 4 deletions

View File

@ -3088,6 +3088,13 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
Type *Ty = II->getType();
unsigned BitWidth = C.getBitWidth();
switch (II->getIntrinsicID()) {
case Intrinsic::abs:
// abs(A) == 0 -> A == 0
if (C.isNullValue())
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),
Constant::getNullValue(Ty));
break;
case Intrinsic::bswap:
// bswap(A) == C -> A == bswap(C)
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),

View File

@ -1094,8 +1094,7 @@ define zeroext i1 @cmpabs2(i64 %val) {
define i1 @abs_intrin_eq_zero(i8 %x) {
; CHECK-LABEL: @abs_intrin_eq_zero(
; CHECK-NEXT: [[ABS:%.*]] = call i8 @llvm.abs.i8(i8 [[X:%.*]], i1 false)
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[ABS]], 0
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
@ -1105,8 +1104,7 @@ define i1 @abs_intrin_eq_zero(i8 %x) {
define i1 @abs_intrin_ne_zero(i8 %x) {
; CHECK-LABEL: @abs_intrin_ne_zero(
; CHECK-NEXT: [[ABS:%.*]] = call i8 @llvm.abs.i8(i8 [[X:%.*]], i1 false)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[ABS]], 0
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)