[llvm] f6b87da - [InstCombine] Fold comparison of abs with int min
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 11:25:06 PDT 2020
Author: Nikita Popov
Date: 2020-09-08T20:23:03+02:00
New Revision: f6b87da0c73fcf7f8f051151ce62d2e07a466a8e
URL: https://github.com/llvm/llvm-project/commit/f6b87da0c73fcf7f8f051151ce62d2e07a466a8e
DIFF: https://github.com/llvm/llvm-project/commit/f6b87da0c73fcf7f8f051151ce62d2e07a466a8e.diff
LOG: [InstCombine] Fold comparison of abs with int min
If the abs is poisoning, this is already folded to true/false.
For non-poisoning abs, we can convert this to a comparison with
the operand.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/abs-intrinsic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 608017b6dca2..74e9525e8ed4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3090,9 +3090,10 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
switch (II->getIntrinsicID()) {
case Intrinsic::abs:
// abs(A) == 0 -> A == 0
- if (C.isNullValue())
+ // abs(A) == INT_MIN -> A == INT_MIN
+ if (C.isNullValue() || C.isMinSignedValue())
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),
- Constant::getNullValue(Ty));
+ ConstantInt::get(Ty, C));
break;
case Intrinsic::bswap:
diff --git a/llvm/test/Transforms/InstCombine/abs-intrinsic.ll b/llvm/test/Transforms/InstCombine/abs-intrinsic.ll
index d63b0a21f217..30e5a9ddab3c 100644
--- a/llvm/test/Transforms/InstCombine/abs-intrinsic.ll
+++ b/llvm/test/Transforms/InstCombine/abs-intrinsic.ll
@@ -275,8 +275,7 @@ define i1 @abs_ne_int_min_poison(i8 %x) {
define i1 @abs_eq_int_min_nopoison(i8 %x) {
; CHECK-LABEL: @abs_eq_int_min_nopoison(
-; CHECK-NEXT: [[ABS:%.*]] = call i8 @llvm.abs.i8(i8 [[X:%.*]], i1 false)
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[ABS]], -128
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], -128
; CHECK-NEXT: ret i1 [[CMP]]
;
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
@@ -286,8 +285,7 @@ define i1 @abs_eq_int_min_nopoison(i8 %x) {
define i1 @abs_ne_int_min_nopoison(i8 %x) {
; CHECK-LABEL: @abs_ne_int_min_nopoison(
-; CHECK-NEXT: [[ABS:%.*]] = call i8 @llvm.abs.i8(i8 [[X:%.*]], i1 false)
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[ABS]], -128
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X:%.*]], -128
; CHECK-NEXT: ret i1 [[CMP]]
;
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
More information about the llvm-commits
mailing list