summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-11-13 10:35:34 -0500
committerSanjay Patel <spatel@rotateright.com>2019-11-13 10:38:42 -0500
commit3d6b53980ce4ee855484fc8ae6ac3f99c85e48c3 (patch)
tree49b07df39b232d4cc7712795227104329fff4d35 /llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
parent1eea3fa063884e36165d122db32228f307793485 (diff)
downloadbcm5719-llvm-3d6b53980ce4ee855484fc8ae6ac3f99c85e48c3.tar.gz
bcm5719-llvm-3d6b53980ce4ee855484fc8ae6ac3f99c85e48c3.zip
[InstCombine] propagate fast-math-flags (FMF) to select when inverting fcmp+select
As noted by the FIXME comment, this is not correct based on our current FMF semantics. We should be propagating FMF from the final value in a sequence (in this case the 'select'). So the behavior even without this patch is wrong, but we did not allow FMF on 'select' until recently. But if we do the correct thing right now in this patch, we'll inevitably introduce regressions because we have not wired up FMF propagation for 'phi' and 'select' in other passes (like SimplifyCFG) or other places in InstCombine. I'm not seeing a better incremental way to make progress. That said, the potential extra damage over the existing wrong behavior from this patch is very limited. AFAIK, the only way to have different FMF on IR in the same function is if we have LTO inlined IR from 2 modules that were compiled using different fast-math settings. As seen in the tests, we may actually see some improvements with this patch because adding the FMF to the 'select' allows matching to min/max intrinsics that were previously missed (in the common case, the 'fcmp' and 'select' should have identical FMF to begin with). Next steps in the transition: Make similar changes in instcombine as needed. Enable phi-to-select FMF propagation in SimplifyCFG. Remove dependencies on fcmp with FMF. Deprecate FMF on fcmp. Differential Revision: https://reviews.llvm.org/D69720
Diffstat (limited to 'llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll')
-rw-r--r--llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll42
1 files changed, 20 insertions, 22 deletions
diff --git a/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll b/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
index 07e12d7c995..d2e1518cda1 100644
--- a/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
@@ -4,8 +4,8 @@
define float @select_max_ugt(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_max_ugt(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp ole float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp arcp ugt float %a, %b
%sel = select arcp i1 %cmp, float %a, float %b
@@ -15,8 +15,8 @@ define float @select_max_ugt(float %a, float %b) {
define float @select_max_uge(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_max_uge(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nnan olt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select nnan i1 [[CMP_INV]], float [[B]], float [[A]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp nnan uge float %a, %b
%sel = select ninf i1 %cmp, float %a, float %b
@@ -25,9 +25,8 @@ define float @select_max_uge(float %a, float %b) {
define float @select_min_ugt(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_min_ugt(
-; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp fast ole float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[A:%.*]], float [[B:%.*]])
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp fast ugt float %a, %b
%sel = select reassoc i1 %cmp, float %b, float %a
@@ -37,8 +36,8 @@ define float @select_min_ugt(float %a, float %b) {
define float @select_min_uge(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_min_uge(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nsz olt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select nsz i1 [[CMP_INV]], float [[A]], float [[B]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp nsz uge float %a, %b
%sel = select fast i1 %cmp, float %b, float %a
@@ -48,8 +47,8 @@ define float @select_min_uge(float %a, float %b) {
define float @select_max_ult(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_max_ult(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp oge float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[A]], float [[B]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp arcp ult float %a, %b
%sel = select ninf nnan i1 %cmp, float %b, float %a
@@ -58,9 +57,8 @@ define float @select_max_ult(float %a, float %b) {
define float @select_max_ule(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_max_ule(
-; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp fast ogt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[A]], float [[B]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[A:%.*]], float [[B:%.*]])
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp fast ule float %a, %b
%sel = select nsz i1 %cmp, float %b, float %a
@@ -70,8 +68,8 @@ define float @select_max_ule(float %a, float %b) {
define float @select_min_ult(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_min_ult(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp nsz oge float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select nsz i1 [[CMP_INV]], float [[B]], float [[A]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp nsz ult float %a, %b
%sel = select fast i1 %cmp, float %a, float %b
@@ -81,8 +79,8 @@ define float @select_min_ult(float %a, float %b) {
define float @select_min_ule(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_min_ule(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp arcp ogt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select arcp i1 [[CMP_INV]], float [[B]], float [[A]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp arcp ule float %a, %b
%sel = select ninf i1 %cmp, float %a, float %b
@@ -92,8 +90,8 @@ define float @select_min_ule(float %a, float %b) {
define float @select_fcmp_une(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_fcmp_une(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp reassoc oeq float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp reassoc une float %a, %b
%sel = select nnan i1 %cmp, float %a, float %b
@@ -103,8 +101,8 @@ define float @select_fcmp_une(float %a, float %b) {
define float @select_fcmp_ueq(float %a, float %b) {
; CHECK-LABEL: define {{[^@]+}}@select_fcmp_ueq(
; CHECK-NEXT: [[CMP_INV:%.*]] = fcmp reassoc one float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_INV]], float [[B]], float [[A]]
-; CHECK-NEXT: ret float [[SEL]]
+; CHECK-NEXT: [[TMP1:%.*]] = select reassoc i1 [[CMP_INV]], float [[B]], float [[A]]
+; CHECK-NEXT: ret float [[TMP1]]
;
%cmp = fcmp reassoc ueq float %a, %b
%sel = select arcp nnan i1 %cmp, float %a, float %b
OpenPOWER on IntegriCloud