[PATCH] D127551: [GISel] Fix unmerging of constants for big endian target

Kai Nacke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 10 16:16:33 PDT 2022


Kai created this revision.
Kai added reviewers: paquette, aemerson, arsenm, nemanjai.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Kai requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Currently, unmerging of constants is always done in little endian style,
which is wrong for big endian targets. This change fixes this.

I need some advice how to test this, as no in-tree big endian target uses
`G_UNMERGE_VALUES`. I discovered this in my m88k backend <https://github.com/redstar/llvm-m88k>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127551

Files:
  llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp


Index: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -1756,9 +1756,13 @@
          "Not enough operands to replace all defs");
   unsigned NumElems = MI.getNumOperands() - 1;
   Builder.setInstrAndDebugLoc(MI);
+  bool IsBigEndianTarget =
+      MI.getParent()->getParent()->getDataLayout().isBigEndian();
   for (unsigned Idx = 0; Idx < NumElems; ++Idx) {
     Register DstReg = MI.getOperand(Idx).getReg();
-    Builder.buildConstant(DstReg, Csts[Idx]);
+    unsigned CstsIdx = IsBigEndianTarget ? bigEndianByteAt(NumElems, Idx)
+                                         : littleEndianByteAt(NumElems, Idx);
+    Builder.buildConstant(DstReg, Csts[CstsIdx]);
   }
 
   MI.eraseFromParent();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127551.436074.patch
Type: text/x-patch
Size: 867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220610/a6f1c3c6/attachment.bin>


More information about the llvm-commits mailing list