Skip to content

Commit 5d5d153

Browse files
author
Hal Finkel
committedJan 10, 2015
[PowerPC] Mark zext of a small scalar load as free
This initial implementation of PPCTargetLowering::isZExtFree marks as free zexts of small scalar loads (that are not sign-extending). This callback is used by SelectionDAGBuilder's RegsForValue::getCopyToRegs, and thus to determine whether a zext or an anyext is used to lower illegally-typed PHIs. Because later truncates of zero-extended values are nops, this allows for the elimination of later unnecessary truncations. Fixes the initial complaint associated with PR22120. llvm-svn: 225584
1 parent 17744c1 commit 5d5d153

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
 

‎llvm/lib/Target/PowerPC/PPCISelLowering.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -9780,6 +9780,26 @@ bool PPCTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const {
97809780
return NumBits1 == 64 && NumBits2 == 32;
97819781
}
97829782

9783+
bool PPCTargetLowering::isZExtFree(SDValue Val, EVT VT2) const {
9784+
// Generally speaking, zexts are not free, but they are free when they can be
9785+
// folded with other operations.
9786+
if (LoadSDNode *LD = dyn_cast<LoadSDNode>(Val)) {
9787+
EVT MemVT = LD->getMemoryVT();
9788+
if ((MemVT == MVT::i1 || MemVT == MVT::i8 || MemVT == MVT::i16 ||
9789+
(Subtarget.isPPC64() && MemVT == MVT::i32)) &&
9790+
(LD->getExtensionType() == ISD::NON_EXTLOAD ||
9791+
LD->getExtensionType() == ISD::ZEXTLOAD))
9792+
return true;
9793+
}
9794+
9795+
// FIXME: Add other cases...
9796+
// - 32-bit shifts with a zext to i64
9797+
// - zext after ctlz, bswap, etc.
9798+
// - zext after and by a constant mask
9799+
9800+
return TargetLowering::isZExtFree(Val, VT2);
9801+
}
9802+
97839803
bool PPCTargetLowering::isLegalICmpImmediate(int64_t Imm) const {
97849804
return isInt<16>(Imm) || isUInt<16>(Imm);
97859805
}

‎llvm/lib/Target/PowerPC/PPCISelLowering.h

+2
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ namespace llvm {
526526
bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
527527
bool isTruncateFree(EVT VT1, EVT VT2) const override;
528528

529+
bool isZExtFree(SDValue Val, EVT VT2) const override;
530+
529531
/// \brief Returns true if it is beneficial to convert a load of a constant
530532
/// to just the constant itself.
531533
bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llc -mcpu=ppc64 < %s | FileCheck %s
2+
target datalayout = "E-m:e-i64:64-n32:64"
3+
target triple = "powerpc64-unknown-linux-gnu"
4+
5+
; Function Attrs: noreturn nounwind
6+
define signext i32 @_Z1fRPc(i8** nocapture dereferenceable(8) %p) #0 {
7+
entry:
8+
%.pre = load i8** %p, align 8
9+
br label %loop
10+
11+
loop: ; preds = %loop.backedge, %entry
12+
%0 = phi i8* [ %.pre, %entry ], [ %.be, %loop.backedge ]
13+
%1 = load i8* %0, align 1
14+
%tobool = icmp eq i8 %1, 0
15+
%incdec.ptr = getelementptr inbounds i8* %0, i64 1
16+
store i8* %incdec.ptr, i8** %p, align 8
17+
%2 = load i8* %incdec.ptr, align 1
18+
%tobool2 = icmp ne i8 %2, 0
19+
%or.cond = and i1 %tobool, %tobool2
20+
br i1 %or.cond, label %if.then3, label %loop.backedge
21+
22+
if.then3: ; preds = %loop
23+
%incdec.ptr4 = getelementptr inbounds i8* %0, i64 2
24+
store i8* %incdec.ptr4, i8** %p, align 8
25+
br label %loop.backedge
26+
27+
loop.backedge: ; preds = %if.then3, %loop
28+
%.be = phi i8* [ %incdec.ptr4, %if.then3 ], [ %incdec.ptr, %loop ]
29+
br label %loop
30+
31+
; CHECK-LABEL: @_Z1fRPc
32+
; CHECK-NOT: rlwinm {{[0-9]+}}, {{[0-9]+}}, 0, 24, 31
33+
; CHECK-NOT: clrlwi {{[0-9]+}}, {{[0-9]+}}, 24
34+
}
35+
36+
attributes #0 = { noreturn nounwind }
37+

0 commit comments

Comments
 (0)
Please sign in to comment.