mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 20:09:46 +00:00
[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.
This commit is contained in:
parent
d5f2743f9a
commit
8a9bdb31d1
@ -3090,9 +3090,10 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
|
|||||||
switch (II->getIntrinsicID()) {
|
switch (II->getIntrinsicID()) {
|
||||||
case Intrinsic::abs:
|
case Intrinsic::abs:
|
||||||
// abs(A) == 0 -> A == 0
|
// 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),
|
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),
|
||||||
Constant::getNullValue(Ty));
|
ConstantInt::get(Ty, C));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Intrinsic::bswap:
|
case Intrinsic::bswap:
|
||||||
|
@ -275,8 +275,7 @@ define i1 @abs_ne_int_min_poison(i8 %x) {
|
|||||||
|
|
||||||
define i1 @abs_eq_int_min_nopoison(i8 %x) {
|
define i1 @abs_eq_int_min_nopoison(i8 %x) {
|
||||||
; CHECK-LABEL: @abs_eq_int_min_nopoison(
|
; 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 [[X:%.*]], -128
|
||||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[ABS]], -128
|
|
||||||
; CHECK-NEXT: ret i1 [[CMP]]
|
; CHECK-NEXT: ret i1 [[CMP]]
|
||||||
;
|
;
|
||||||
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
|
%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) {
|
define i1 @abs_ne_int_min_nopoison(i8 %x) {
|
||||||
; CHECK-LABEL: @abs_ne_int_min_nopoison(
|
; 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 [[X:%.*]], -128
|
||||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[ABS]], -128
|
|
||||||
; CHECK-NEXT: ret i1 [[CMP]]
|
; CHECK-NEXT: ret i1 [[CMP]]
|
||||||
;
|
;
|
||||||
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
|
%abs = call i8 @llvm.abs.i8(i8 %x, i1 false)
|
||||||
|
Loading…
Reference in New Issue
Block a user