1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

bpf: fix a bug in dag2dag optimization for loads from readonly section

The reference '&' is missing in the function parameter. If there are
back-to-back optimizations in terms of dag node list like below:
  t29: i64,ch = load<LD4[bitcast (%struct.test_t* @test.t to i8*)+12](dereferenceable), zext from i32> t3, t43, undef:i64
  t34: i64,ch = load<LD4[bitcast (%struct.test_t* @test.t to i8*)](dereferenceable), zext from i32> t3, t41, undef:i64
The bug will trigger a segfault for the added test case remove_truncate_5.ll:
  LLVMSymbolizer: error reading file: No such file or directory
  #0 0x000000000241c4d9 (llc+0x241c4d9)
  #1 0x000000000241c56a (llc+0x241c56a)
  #2 0x000000000241aa50 (llc+0x241aa50)
  ...
  #22 0x0000000000fd5edf (llc+0xfd5edf)
  #23 0x00007f0fe03bec05 __libc_start_main (/lib64/libc.so.6+0x21c05)
  #24 0x0000000000fd3e69 (llc+0xfd3e69)
  ...
  Segmentation fault

Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 325267
This commit is contained in:
Yonghong Song 2018-02-15 17:06:45 +00:00
parent ac320360e4
commit 419f317716
2 changed files with 57 additions and 4 deletions

View File

@ -65,9 +65,9 @@ private:
bool SelectFIAddr(SDValue Addr, SDValue &Base, SDValue &Offset);
// Node preprocessing cases
void PreprocessLoad(SDNode *Node, SelectionDAG::allnodes_iterator I);
void PreprocessLoad(SDNode *Node, SelectionDAG::allnodes_iterator &I);
void PreprocessCopyToReg(SDNode *Node);
void PreprocessTrunc(SDNode *Node, SelectionDAG::allnodes_iterator I);
void PreprocessTrunc(SDNode *Node, SelectionDAG::allnodes_iterator &I);
// Find constants from a constant structure
typedef std::vector<unsigned char> val_vec_type;
@ -238,7 +238,7 @@ void BPFDAGToDAGISel::Select(SDNode *Node) {
}
void BPFDAGToDAGISel::PreprocessLoad(SDNode *Node,
SelectionDAG::allnodes_iterator I) {
SelectionDAG::allnodes_iterator &I) {
union {
uint8_t c[8];
uint16_t s;
@ -511,7 +511,7 @@ void BPFDAGToDAGISel::PreprocessCopyToReg(SDNode *Node) {
}
void BPFDAGToDAGISel::PreprocessTrunc(SDNode *Node,
SelectionDAG::allnodes_iterator I) {
SelectionDAG::allnodes_iterator &I) {
ConstantSDNode *MaskN = dyn_cast<ConstantSDNode>(Node->getOperand(1));
if (!MaskN)
return;

View File

@ -0,0 +1,53 @@
; RUN: llc < %s -march=bpfel | FileCheck -check-prefixes=CHECK %s
; Source code:
; struct test_t {
; int a;
; char b;
; int c;
; char d;
; };
; void foo(void *);
; void test() {
; struct test_t t = {.a = 5};
; foo(&t);
; }
%struct.test_t = type { i32, i8, i32, i8 }
@test.t = private unnamed_addr constant %struct.test_t { i32 5, i8 0, i32 0, i8 0 }, align 4
; Function Attrs: nounwind
define dso_local void @test() local_unnamed_addr #0 {
; CHECK-LABEL: test:
%1 = alloca %struct.test_t, align 4
%2 = bitcast %struct.test_t* %1 to i8*
call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %2) #3
call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 %2, i8* align 4 bitcast (%struct.test_t* @test.t to i8*), i64 16, i1 false)
; CHECK: r1 = 0
; CHECK: r1 <<= 32
; CHECK: r2 = r1
; CHECK: r2 |= 0
; CHECK: *(u64 *)(r10 - 8) = r2
; CHECK: r1 |= 5
; CHECK: *(u64 *)(r10 - 16) = r1
call void @foo(i8* nonnull %2) #3
; CHECK: call foo
call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %2) #3
ret void
}
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1
declare dso_local void @foo(i8*) local_unnamed_addr
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
attributes #0 = { nounwind }
attributes #1 = { argmemonly nounwind }
attributes #3 = { nounwind }