[llvm] [GlobalISel] replace right identity X * -1.0 with fneg(x) (PR #80526)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 02:27:00 PST 2024
================
@@ -0,0 +1,109 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
+# RUN: llc -march=amdgcn -mcpu=gfx1010 -run-pass=amdgpu-postlegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=CHECK
+
+---
+name: test_neg_one_f16
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $sgpr0
+
+ ; CHECK-LABEL: name: test_neg_one_f16
+ ; CHECK: liveins: $sgpr0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $sgpr0
+ ; CHECK-NEXT: %x:_(s16) = G_TRUNC [[COPY]](s32)
+ ; CHECK-NEXT: %d:_(s16) = G_FNEG %x
+ ; CHECK-NEXT: %ext:_(s32) = G_ANYEXT %d(s16)
+ ; CHECK-NEXT: $sgpr0 = COPY %ext(s32)
+ %0:_(s32) = COPY $sgpr0
+ %x:_(s16) = G_TRUNC %0:_(s32)
+ %y:_(s16) = G_FCONSTANT half -1.0
+ %d:_(s16) = G_FMUL %x, %y
+ %ext:_(s32) = G_ANYEXT %d:_(s16)
+ $sgpr0 = COPY %ext
+
+...
+
+---
+name: test_neg_one_f32
+body: |
+ bb.0:
+ liveins: $sgpr0
+
+ ; CHECK-LABEL: name: test_neg_one_f32
+ ; CHECK: liveins: $sgpr0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $sgpr0
+ ; CHECK-NEXT: [[FNEG:%[0-9]+]]:_(s32) = G_FNEG [[COPY]]
+ ; CHECK-NEXT: $sgpr0 = COPY [[FNEG]](s32)
+ %0:_(s32) = COPY $sgpr0
+ %1:_(s32) = G_FCONSTANT float -1.0
+ %2:_(s32) = G_FMUL %0, %1
+ $sgpr0 = COPY %2(s32)
+
+...
+
+---
+name: test_neg_one_f64
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $sgpr0
+
+ ; CHECK-LABEL: name: test_neg_one_f64
+ ; CHECK: liveins: $sgpr0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $sgpr0
+ ; CHECK-NEXT: %x:_(s64) = G_ANYEXT [[COPY]](s32)
+ ; CHECK-NEXT: %d:_(s64) = G_FNEG %x
+ ; CHECK-NEXT: %ext:_(s32) = G_TRUNC %d(s64)
+ ; CHECK-NEXT: $sgpr0 = COPY %ext(s32)
+ %0:_(s32) = COPY $sgpr0
+ %x:_(s64) = G_ANYEXT %0:_(s32)
+ %y:_(s64) = G_FCONSTANT double -1.0
+ %d:_(s64) = G_FMUL %x, %y
+ %ext:_(s32) = G_TRUNC %d:_(s64)
+ $sgpr0 = COPY %ext
+
+...
+
+---
+name: test_neg_ten_f32
+body: |
+ bb.0:
+ liveins: $sgpr0
+
+ ; CHECK-LABEL: name: test_neg_ten_f32
+ ; CHECK: liveins: $sgpr0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $sgpr0
+ ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_FCONSTANT float -1.000000e+01
+ ; CHECK-NEXT: [[FMUL:%[0-9]+]]:_(s32) = G_FMUL [[COPY]], [[C]]
+ ; CHECK-NEXT: $sgpr0 = COPY [[FMUL]](s32)
+ %0:_(s32) = COPY $sgpr0
+ %1:_(s32) = G_FCONSTANT float -10.0
+ %2:_(s32) = G_FMUL %0, %1
+ $sgpr0 = COPY %2(s32)
+
+...
+
+---
+name: test_neg_fract_f32
+body: |
+ bb.0:
+ liveins: $sgpr0
+
+ ; CHECK-LABEL: name: test_neg_fract_f32
+ ; CHECK: liveins: $sgpr0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $sgpr0
+ ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_FCONSTANT float -5.000000e-01
+ ; CHECK-NEXT: [[FMUL:%[0-9]+]]:_(s32) = G_FMUL [[COPY]], [[C]]
+ ; CHECK-NEXT: $sgpr0 = COPY [[FMUL]](s32)
+ %0:_(s32) = COPY $sgpr0
+ %1:_(s32) = G_FCONSTANT float -0.5
+ %2:_(s32) = G_FMUL %0, %1
+ $sgpr0 = COPY %2(s32)
+
+...
----------------
arsenm wrote:
Vector case wouldn't hurt
https://github.com/llvm/llvm-project/pull/80526
More information about the llvm-commits
mailing list