This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix inconsistent ImmMustBeMultipleOf for same instruction
ClosedPublic

Authored by ZhangKang on Nov 19 2018, 6:59 PM.

Details

Summary

There are 4 instruction which has Inconsistent ImmMustBeMultipleOf in the function PPCInstrInfo::instrHasImmForm, they are LFS, LFD, STFS, STFD.

For example LFS:

2651  bool PPCInstrInfo::instrHasImmForm(const MachineInstr &MI,
                                   ImmInstrInfo &III, bool PostRA) const {
2653  unsigned Opc = MI.getOpcode();
      ...
2661  III.ImmMustBeMultipleOf = 1;
      ...
  
2664    switch (Opc) {
      ...
2880      case PPC::LFSX: III.ImmOpcode = PPC::LFS; break;
      ...
      
2961      case PPC::STXSSPX:
2976        III.ImmMustBeMultipleOf = 4;
      ...
2977        switch(Opc) {
      ...
2983          case PPC::LXSSPX:
2984            if (PostRA) {
2985              if (isVFReg(MI.getOperand(0).getReg()))
2986                III.ImmOpcode = PPC::LXSSP;
2987              else
2988                III.ImmOpcode = PPC::LFS;
2989              break;
2990            }
      ...
            }
      ...        
        }
      ...    
      }

For the ImmInstrInfo::ImmMustBeMultipleOf is used to describe the immediate multiple information of the instruction LFS. So for the same instruction LFS, it should have same immediate multiple information.

But from above code, we can see in the line 2880, the instruction LFS has the immediate multiple 1 byte, but in the line 2988, its value is 4 byte. They are inconsistent.

This bug will result in below pattern can not be optimized.

addi   r2, 99
lxsspx f1, 0, r2

In fact, this pattern should be optimized to:

lfs f1, 99(r2)

Diff Detail

Repository
rL LLVM

Event Timeline

ZhangKang created this revision.Nov 19 2018, 6:59 PM
nemanjai accepted this revision.Nov 20 2018, 6:44 AM

LGTM.

This revision is now accepted and ready to land.Nov 20 2018, 6:44 AM
This revision was automatically updated to reflect the committed changes.
ZhangKang reopened this revision.Nov 27 2018, 12:33 AM

The test case does not use -mtriple=powerpc64-unknown-linux-gnu option, so on the platform except PowerPC, we will get error. I should modify the test case command line to use the option -mtriple. I have reverted this commit.

This revision is now accepted and ready to land.Nov 27 2018, 12:33 AM

Add the optiion -mtriple=powerpc64le-unknown-linux-gnu.

steven.zhang accepted this revision.Dec 2 2018, 7:14 PM
steven.zhang added a subscriber: steven.zhang.

LGTM.

This revision was automatically updated to reflect the committed changes.