Skip to content

Commit 39a5993

Browse files
committed
[Xtensa] Fix ConstantPool lowering for aggregate constants.
1 parent df4263f commit 39a5993

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ def : Pat<(i32 (extloadi16 addr_ish2:$addr)), (L16UI addr_ish2:$addr)>;
314314
def : Pat<(i32 (load (add i32:$s, (Xtensa_pcrel_wrapper tconstpool:$in)))),
315315
(L32I (ADD i32:$s, (L32R tconstpool:$in)), 0)>;
316316

317+
// In some cases load from aggregate constant pattern maybe not matched.
318+
// It is assumed that load 4-byte constant pattern is already
319+
// applied, so this is the case of load from the aggregate constant.
320+
// We just load an address of aggregate constant.
321+
let AddedComplexity = -1 in
322+
def : Pat<(Xtensa_pcrel_wrapper tconstpool:$in), (L32R tconstpool:$in)>;
323+
317324
//===----------------------------------------------------------------------===//
318325
// Conditional branch instructions
319326
//===----------------------------------------------------------------------===//
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc -mtriple=xtensa -mattr=+fp -O1 -verify-machineinstrs < %s \
2+
; RUN: | FileCheck %s
3+
4+
define float @select_fp_consts(float %x) {
5+
; CHECK: .literal_position
6+
; CHECK-NEXT: .literal .LCPI0_0, 0
7+
; CHECK-NEXT: .literal .LCPI0_1, .LCP0_0
8+
; CHECK-LABEL: select_fp_consts:
9+
; CHECK: # %bb.0: # %entry
10+
; CHECK-NEXT: l32r a8, .LCPI0_0
11+
; CHECK-NEXT: wfr f8, a8
12+
; CHECK-NEXT: wfr f9, a2
13+
; CHECK-NEXT: ule.s b0, f9, f8
14+
; CHECK-NEXT: bf b0, .LBB0_2
15+
; CHECK-NEXT: # %bb.1: # %entry
16+
; CHECK-NEXT: movi a8, 0
17+
; CHECK-NEXT: j .LBB0_3
18+
; CHECK-NEXT: .LBB0_2:
19+
; CHECK-NEXT: movi a8, 4
20+
; CHECK-NEXT: .LBB0_3: # %entry
21+
; CHECK-NEXT: l32r a9, .LCPI0_1
22+
; CHECK-NEXT: add a8, a9, a8
23+
; CHECK-NEXT: l32i a2, a8, 0
24+
; CHECK-NEXT: ret
25+
entry:
26+
%c = fcmp ogt float %x, 0.000000e+00
27+
%r = select i1 %c, float -1.000000e+00, float 1.000000e+00
28+
ret float %r
29+
}

0 commit comments

Comments
 (0)