[PATCH] D123588: [InstCombine] fix tests in fneg.ll

Chenbing.Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 12 04:51:21 PDT 2022


Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: spatel, Krishnakariya, benshi001.
Chenbing.Zheng added a project: LLVM.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.

Add flag 'nsz' in select, so that it can be fold to fabs.

In D101727 <https://reviews.llvm.org/D101727>, it fix Incorrect transformation of fabs, so I think
'nsz' should be added in select.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123588

Files:
  llvm/test/Transforms/InstCombine/fneg.ll


Index: llvm/test/Transforms/InstCombine/fneg.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fneg.ll
+++ llvm/test/Transforms/InstCombine/fneg.ll
@@ -714,18 +714,15 @@
   ret float %fneg1
 }
 
-; TODO: This should reduce to fneg-of-fabs.
-
 define float @fnabs(float %a) {
 ; CHECK-LABEL: @fnabs(
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[A_NEG:%.*]] = fneg fast float [[A]]
-; CHECK-NEXT:    [[FNEG1:%.*]] = select fast i1 [[CMP]], float [[A]], float [[A_NEG]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call nsz float @llvm.fabs.f32(float [[A:%.*]])
+; CHECK-NEXT:    [[FNEG1:%.*]] = fneg fast float [[TMP1]]
 ; CHECK-NEXT:    ret float [[FNEG1]]
 ;
   %fneg = fneg float %a
   %cmp = fcmp olt float %a, %fneg
-  %sel = select i1 %cmp, float %fneg, float %a
+  %sel = select nsz i1 %cmp, float %fneg, float %a
   %fneg1 = fneg fast float %sel
   ret float %fneg1
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123588.422179.patch
Type: text/x-patch
Size: 967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220412/4385ca03/attachment.bin>


More information about the llvm-commits mailing list