[PATCH] D76982: [PowerPC] Update Alignment of ReuseLoadInfo in PPCTargetLowering::LowerFP_TO_INTForReuse

Kai Luo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 03:46:49 PDT 2020


lkail created this revision.
lkail added reviewers: nemanjai, steven.zhang, hfinkel, PowerPC.
Herald added subscribers: llvm-commits, shchenz, kbarton, hiraditya.
Herald added a project: LLVM.

Current PowerPC backend fails to compile the attached test case, hitting an assertion error

  llvm-project/llvm/include/llvm/Support/Alignment.h:78: llvm::Align::Align(uint64_t): Assertion `Value > 0 && "Value must not be 0"' failed.

PowerPC backend wants to emit such code sequence

  fctiwz ...
  stfiwx ...
  lfiwax ...

for LLVM IR

  %b = fptosi float %a to i32
  %c = sitofp i32 %b to float

on targets without VSX support(e.g. building a linux kernel). When emitting `stfiwx`, `Alignment` of `ReuseLoadInfo` is supposed to be updated in `PPCTargetLowering::LowerFP_TO_INTForReuse` so that following emit of `lfiwax` can know the alignment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76982

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/kernel-fp-round.ll


Index: llvm/test/CodeGen/PowerPC/kernel-fp-round.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/kernel-fp-round.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
+; RUN:   -mattr=-vsx -ppc-asm-full-reg-names < %s | FileCheck %s
+
+define float @test(float %arg) {
+; CHECK-LABEL: test:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    fctiwz f0, f1
+; CHECK-NEXT:    addi r3, r1, -4
+; CHECK-NEXT:    stfiwx f0, 0, r3
+; CHECK-NEXT:    lfiwax f0, 0, r3
+; CHECK-NEXT:    fcfids f1, f0
+; CHECK-NEXT:    blr
+entry:
+  %conv = fptosi float %arg to i32
+  %res = sitofp i32 %conv to float
+  ret float %res
+}
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -7897,10 +7897,12 @@
 
   // Emit a store to the stack slot.
   SDValue Chain;
+  unsigned Alignment = 0;
   if (i32Stack) {
     MachineFunction &MF = DAG.getMachineFunction();
     MachineMemOperand *MMO =
       MF.getMachineMemOperand(MPI, MachineMemOperand::MOStore, 4, 4);
+    Alignment = 4;
     SDValue Ops[] = { DAG.getEntryNode(), Tmp, FIPtr };
     Chain = DAG.getMemIntrinsicNode(PPCISD::STFIWX, dl,
               DAG.getVTList(MVT::Other), Ops, MVT::i32, MMO);
@@ -7918,6 +7920,7 @@
   RLI.Chain = Chain;
   RLI.Ptr = FIPtr;
   RLI.MPI = MPI;
+  RLI.Alignment = Alignment;
 }
 
 /// Custom lowers floating point to integer conversions to use


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76982.253326.patch
Type: text/x-patch
Size: 1676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200328/2db3d042/attachment.bin>


More information about the llvm-commits mailing list