llvm.org GIT mirror llvm / f53ef72
[PowerPC] Look through copies for compare elimination We currently miss the opportunities for optmizing comparisons in the peephole optimizer if the input is the result of a COPY since we look for record-form versions of the producing instruction. This patch simply lets the optimization peek through copies. Differential revision: https://reviews.llvm.org/D59633 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362438 91177308-0d34-0410-b5e6-96231b3b80d8 Nemanja Ivanovic 3 months ago
2 changed file(s) with 35 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
16521652 if (OpC == PPC::FCMPUS || OpC == PPC::FCMPUD)
16531653 return false;
16541654
1655 const TargetRegisterInfo *TRI = &getRegisterInfo();
16551656 // The record forms set the condition register based on a signed comparison
16561657 // with zero (so says the ISA manual). This is not as straightforward as it
16571658 // seems, however, because this is always a 64-bit comparison on PPC64, even
16641665 bool is32BitSignedCompare = OpC == PPC::CMPWI || OpC == PPC::CMPW;
16651666 bool is32BitUnsignedCompare = OpC == PPC::CMPLWI || OpC == PPC::CMPLW;
16661667 bool is64BitUnsignedCompare = OpC == PPC::CMPLDI || OpC == PPC::CMPLD;
1668
1669 // Look through copies unless that gets us to a physical register.
1670 unsigned ActualSrc = TRI->lookThruCopyLike(SrcReg, MRI);
1671 if (TargetRegisterInfo::isVirtualRegister(ActualSrc))
1672 SrcReg = ActualSrc;
16671673
16681674 // Get the unique definition of SrcReg.
16691675 MachineInstr *MI = MRI->getUniqueVRegDef(SrcReg);
17931799 }
17941800
17951801 // Search for Sub.
1796 const TargetRegisterInfo *TRI = &getRegisterInfo();
17971802 --I;
17981803
17991804 // Get ready to iterate backward from CmpInstr.
0 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
1 ; RUN: -mcpu=pwr8 -ppc-asm-full-reg-names < %s | FileCheck %s
2
3 define dso_local signext i32 @func(i32 zeroext %x, i32 zeroext %y) local_unnamed_addr {
4 ; CHECK-LABEL: func
5 ; CHECK: or. {{r[0-9]+}}, r4, r3
6 ; CHECK-NOT: cmplwi
7 ; CHECK: blr
8 entry:
9 %or = or i32 %y, %x
10 %tobool = icmp eq i32 %or, 0
11 br i1 %tobool, label %if.else, label %if.then
12
13 if.then: ; preds = %entry
14 %call = tail call signext i32 bitcast (i32 (...)* @f1 to i32 ()*)()
15 br label %return
16
17 if.else: ; preds = %entry
18 %call1 = tail call signext i32 bitcast (i32 (...)* @f2 to i32 ()*)()
19 br label %return
20
21 return: ; preds = %if.else, %if.then
22 %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
23 ret i32 %retval.0
24 }
25
26 declare signext i32 @f1(...) local_unnamed_addr
27
28 declare signext i32 @f2(...) local_unnamed_addr