Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 9875a79

Browse files
committed
[DAGCombine] Don't combine sext with extload if sextload is not supported and extload has multi users
In function DAGCombiner::visitSIGN_EXTEND_INREG, sext can be combined with extload even if sextload is not supported by target, then if sext is the only user of extload, there is no big difference, no harm no benefit. if extload has more than one user, the combined sextload may block extload from combining with other zext, causes extra zext instructions generated. As demonstrated by the attached test case. This patch add the constraint that when sextload is not supported by target, sext can only be combined with extload if it is the only user of extload. Differential Revision: https://reviews.llvm.org/D39108 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316802 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9a8a815 commit 9875a79

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8274,10 +8274,14 @@ SDValue DAGCombiner::visitSIGN_EXTEND_INREG(SDNode *N) {
82748274
}
82758275

82768276
// fold (sext_inreg (extload x)) -> (sextload x)
8277+
// If sextload is not supported by target, we can only do the combine when
8278+
// load has one use. Doing otherwise can block folding the extload with other
8279+
// extends that the target does support.
82778280
if (ISD::isEXTLoad(N0.getNode()) &&
82788281
ISD::isUNINDEXEDLoad(N0.getNode()) &&
82798282
EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
8280-
((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
8283+
((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile() &&
8284+
N0.hasOneUse()) ||
82818285
TLI.isLoadExtLegal(ISD::SEXTLOAD, VT, EVT))) {
82828286
LoadSDNode *LN0 = cast<LoadSDNode>(N0);
82838287
SDValue ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, SDLoc(N), VT,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc --mtriple=powerpc64le-linux-gnu < %s | FileCheck %s
2+
3+
; It tests in function DAGCombiner::visitSIGN_EXTEND_INREG
4+
; signext will not be combined with extload, and causes extra zext.
5+
6+
declare void @g(i32 signext)
7+
8+
define void @foo(i8* %p) {
9+
entry:
10+
br label %while.body
11+
12+
while.body:
13+
%0 = load i8, i8* %p, align 1
14+
%conv = zext i8 %0 to i32
15+
%cmp = icmp sgt i8 %0, 0
16+
br i1 %cmp, label %if.then, label %while.body
17+
; CHECK: lbz
18+
; CHECK: extsb.
19+
; CHECK-NOT: rlwinm
20+
; CHECK: ble
21+
22+
if.then:
23+
tail call void @g(i32 signext %conv)
24+
br label %while.body
25+
}
26+

0 commit comments

Comments
 (0)