[InstCombine] add folds for fcmp Pred fabs(X), 0.0

Similar to rL346321, we had folds for the ordered
versions of these compares already, so add the
unordered siblings for completeness.

llvm-svn: 346324
This commit is contained in:
Sanjay Patel 2018-11-07 15:33:03 +00:00
parent 16a527e7de
commit fa5f146872
2 changed files with 10 additions and 4 deletions

View File

@ -5302,10 +5302,18 @@ static Instruction *foldFabsWithFcmpZero(FCmpInst &I) {
// fabs(X) > 0.0 --> X != 0.0
return new FCmpInst(FCmpInst::FCMP_ONE, X, I.getOperand(1));
case FCmpInst::FCMP_UGT:
// fabs(X) u> 0.0 --> X u!= 0.0
return new FCmpInst(FCmpInst::FCMP_UNE, X, I.getOperand(1));
case FCmpInst::FCMP_OLE:
// fabs(X) <= 0.0 --> X == 0.0
return new FCmpInst(FCmpInst::FCMP_OEQ, X, I.getOperand(1));
case FCmpInst::FCMP_ULE:
// fabs(X) u<= 0.0 --> X u== 0.0
return new FCmpInst(FCmpInst::FCMP_UEQ, X, I.getOperand(1));
case FCmpInst::FCMP_OGE:
// fabs(X) >= 0.0 --> !isnan(X)
assert(!I.hasNoNaNs() && "fcmp should have simplified");

View File

@ -199,8 +199,7 @@ define <2 x i1> @fabs_ole(<2 x float> %a) {
define <2 x i1> @fabs_ule(<2 x float> %a) {
; CHECK-LABEL: @fabs_ule(
; CHECK-NEXT: [[CALL:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[A:%.*]])
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf arcp ule <2 x float> [[CALL]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq <2 x float> [[A:%.*]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%call = call <2 x float> @llvm.fabs.v2f32(<2 x float> %a)
@ -220,8 +219,7 @@ define i1 @fabs_ogt(double %a) {
define i1 @fabs_ugt(double %a) {
; CHECK-LABEL: @fabs_ugt(
; CHECK-NEXT: [[CALL:%.*]] = call double @llvm.fabs.f64(double [[A:%.*]])
; CHECK-NEXT: [[CMP:%.*]] = fcmp reassoc ninf ugt double [[CALL]], 0.000000e+00
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[A:%.*]], 0.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
;
%call = call double @llvm.fabs.f64(double %a)