[llvm] [AArch64][ARM] Avoid some APFloat copies in tablegen patterns. NFC. (PR #114416)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 08:32:12 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-backend-aarch64

Author: Simon Pilgrim (RKSimon)

<details>
<summary>Changes</summary>

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
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);
     }]>;
 

``````````

</details>


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


More information about the llvm-commits mailing list