Skip to content

[AArch64][ARM] Avoid some APFloat copies in tablegen patterns. NFC. #114416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

RKSimon
Copy link
Collaborator

@RKSimon RKSimon commented Oct 31, 2024

Either the N->getValueAPF() was being unused or we were failing to make use of it returning a const APFloat&

@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-backend-aarch64

Author: Simon Pilgrim (RKSimon)

Changes

Either the N->getValueAPF() was being unused or we were failing to make use of it returning a const APFloat&


Full diff: https://github.com/llvm/llvm-project/pull/114416.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64InstrFormats.td (+3-7)
  • (modified) llvm/lib/Target/ARM/ARMInstrVFP.td (+4-8)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrFormats.td b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
index 837d737b28588c..031d94f5b19c39 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrFormats.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrFormats.td
@@ -1390,14 +1390,12 @@ def arith_uxtx : ComplexPattern<i64, 2, "SelectArithUXTXRegister", []>;
 // Floating-point immediate.
 
 def fpimm16XForm : SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = AArch64_AM::getFP16Imm(InVal);
+      uint32_t enc = AArch64_AM::getFP16Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>;
 
 def fpimm32XForm : SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = AArch64_AM::getFP32Imm(InVal);
+      uint32_t enc = AArch64_AM::getFP32Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>;
 
@@ -1409,8 +1407,7 @@ def fpimm32SIMDModImmType4XForm : SDNodeXForm<fpimm, [{
     }]>;
 
 def fpimm64XForm : SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = AArch64_AM::getFP64Imm(InVal);
+      uint32_t enc = AArch64_AM::getFP64Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>;
 
@@ -1681,7 +1678,6 @@ def simdimmtype10 : Operand<i32>,
       return AArch64_AM::isAdvSIMDModImmType10(
                  Imm.bitcastToAPInt().getZExtValue());
     }], SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
       uint32_t enc = AArch64_AM::encodeAdvSIMDModImmType10(N->getValueAPF()
                                                            .bitcastToAPInt()
                                                            .getZExtValue());
diff --git a/llvm/lib/Target/ARM/ARMInstrVFP.td b/llvm/lib/Target/ARM/ARMInstrVFP.td
index 3094a4db2b4d12..46127f972a0ce1 100644
--- a/llvm/lib/Target/ARM/ARMInstrVFP.td
+++ b/llvm/lib/Target/ARM/ARMInstrVFP.td
@@ -46,8 +46,7 @@ def vfp_f16imm : Operand<f16>,
                  PatLeaf<(f16 fpimm), [{
       return ARM_AM::getFP16Imm(N->getValueAPF()) != -1;
     }], SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = ARM_AM::getFP16Imm(InVal);
+      uint32_t enc = ARM_AM::getFP16Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>> {
   let PrintMethod = "printFPImmOperand";
@@ -55,8 +54,7 @@ def vfp_f16imm : Operand<f16>,
 }
 
 def vfp_f32f16imm_xform : SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = ARM_AM::getFP32FP16Imm(InVal);
+      uint32_t enc = ARM_AM::getFP32FP16Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>;
 
@@ -65,8 +63,7 @@ def vfp_f32f16imm : PatLeaf<(f32 fpimm), [{
     }], vfp_f32f16imm_xform>;
 
 def vfp_f32imm_xform : SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = ARM_AM::getFP32Imm(InVal);
+      uint32_t enc = ARM_AM::getFP32Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>;
 
@@ -88,8 +85,7 @@ def vfp_f32imm : Operand<f32>,
 }
 
 def vfp_f64imm_xform : SDNodeXForm<fpimm, [{
-      APFloat InVal = N->getValueAPF();
-      uint32_t enc = ARM_AM::getFP64Imm(InVal);
+      uint32_t enc = ARM_AM::getFP64Imm(N->getValueAPF());
       return CurDAG->getTargetConstant(enc, SDLoc(N), MVT::i32);
     }]>;
 

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel like capitalising Enc that would be an improvement too. Either way LGTM, cheers.

Either the N->getValueAPF() was being unused or we were failing to make use of it returning a const APFloat&
@RKSimon RKSimon force-pushed the dagpattern-avoid-apfloat-copies branch from e9f22cb to b207bfb Compare November 1, 2024 17:06
@RKSimon RKSimon merged commit 8634e35 into llvm:main Nov 1, 2024
6 of 8 checks passed
@RKSimon RKSimon deleted the dagpattern-avoid-apfloat-copies branch November 1, 2024 18:15
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
…lvm#114416)

Either the N->getValueAPF() was being unused or we were failing to make use of it returning a const APFloat&
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…lvm#114416)

Either the N->getValueAPF() was being unused or we were failing to make use of it returning a const APFloat&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants