[PATCH] D40012: [InstSimplify] More fcmp cases when comparing against negative constants.
Paul Walker via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 09:21:01 PST 2017
paulwalker-arm updated this revision to Diff 124589.
paulwalker-arm edited the summary of this revision.
paulwalker-arm added a comment.
Broke out the isNegative case into its own block so that more conditions can be handled when it's known the constant is non-zero. Removed my original tests and updated the existing ones to reflect the optimised output.
https://reviews.llvm.org/D40012
Files:
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/floating-point-compare.ll
Index: test/Transforms/InstSimplify/floating-point-compare.ll
===================================================================
--- test/Transforms/InstSimplify/floating-point-compare.ll
+++ test/Transforms/InstSimplify/floating-point-compare.ll
@@ -276,42 +276,34 @@
define i1 @known_positive_olt_with_negative_constant(double %a) {
; CHECK-LABEL: @known_positive_olt_with_negative_constant(
-; CHECK-NEXT: [[CALL:%.*]] = call double @llvm.fabs.f64(double %a)
-; CHECK-NEXT: [[CMP:%.*]] = fcmp olt double [[CALL]], -1.000000e+00
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
%call = call double @llvm.fabs.f64(double %a)
%cmp = fcmp olt double %call, -1.0
ret i1 %cmp
}
define <2 x i1> @known_positive_ole_with_negative_constant_splat_vec(<2 x double> %a) {
; CHECK-LABEL: @known_positive_ole_with_negative_constant_splat_vec(
-; CHECK-NEXT: [[CALL:%.*]] = call <2 x double> @llvm.fabs.v2f64(<2 x double> %a)
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ole <2 x double> [[CALL]], <double -2.000000e+00, double -2.000000e+00>
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%call = call <2 x double> @llvm.fabs.v2f64(<2 x double> %a)
%cmp = fcmp ole <2 x double> %call, <double -2.0, double -2.0>
ret <2 x i1> %cmp
}
define i1 @known_positive_ugt_with_negative_constant(double %a) {
; CHECK-LABEL: @known_positive_ugt_with_negative_constant(
-; CHECK-NEXT: [[CALL:%.*]] = call double @llvm.fabs.f64(double %a)
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt double [[CALL]], -3.000000e+00
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%call = call double @llvm.fabs.f64(double %a)
%cmp = fcmp ugt double %call, -3.0
ret i1 %cmp
}
define <2 x i1> @known_positive_uge_with_negative_constant_splat_vec(<2 x double> %a) {
; CHECK-LABEL: @known_positive_uge_with_negative_constant_splat_vec(
-; CHECK-NEXT: [[CALL:%.*]] = call <2 x double> @llvm.fabs.v2f64(<2 x double> %a)
-; CHECK-NEXT: [[CMP:%.*]] = fcmp uge <2 x double> [[CALL]], <double -4.000000e+00, double -4.000000e+00>
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%call = call <2 x double> @llvm.fabs.v2f64(<2 x double> %a)
%cmp = fcmp uge <2 x double> %call, <double -4.0, double -4.0>
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -3378,6 +3378,23 @@
default:
break;
}
+ } else if (C->isNegative()) {
+ switch (Pred) {
+ case FCmpInst::FCMP_UGE:
+ case FCmpInst::FCMP_UGT:
+ // (X >= 0) implies (X > C) when (C < 0)
+ if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ return getTrue(RetTy);
+ break;
+ case FCmpInst::FCMP_OLE:
+ case FCmpInst::FCMP_OLT:
+ // (X >= 0) implies !(X < C) when (C < 0)
+ if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ return getFalse(RetTy);
+ break;
+ default:
+ break;
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40012.124589.patch
Type: text/x-patch
Size: 3139 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171128/e961f79f/attachment.bin>
More information about the llvm-commits
mailing list