Skip to content

Commit

Permalink
Add some XFAILED testcase for poor code generation
Browse files Browse the repository at this point in the history
See #290 and #292
  • Loading branch information
arichardson committed Feb 18, 2019
1 parent cf608f6 commit 28b9f7c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
13 changes: 10 additions & 3 deletions llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,20 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin,
for (IterTy I = Begin; I != End;) {
IterTy CurrI = I;
++I;

LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": checking instruction for delay slot: ";
CurrI->dump());
// skip debug value
if (CurrI->isDebugInstr())
if (CurrI->isDebugInstr()) {
LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": ignoring debug instruction for delay slot: ";
CurrI->dump());
continue;
}

if (terminateSearch(*CurrI))
if (terminateSearch(*CurrI)) {
LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": should terminate search: ";
CurrI->dump());
break;
}

assert((!CurrI->isCall() && !CurrI->isReturn() && !CurrI->isBranch()) &&
"Cannot put calls, returns or branches in delay slot.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %cheri_clang -S -o - -O2 %s -mllvm -debug-only="mips-delay-slot-filler" -mllvm -print-before="mips-delay-slot-filler" -mllvm -print-after="mips-delay-slot-filler" | FileCheck %s
// REQUIRES: asserts
// XFAIL: *
// https://github.com/CTSRD-CHERI/llvm-project/issues/290

int *__capability test(int *__capability inCap, int test, int inInt) {
int *__capability
ret = inCap;
if (test) {
ret += inInt + 4;
}
return ret;
}

// CHECK-LABEL: # %bb.0: # %entry
// CHECK-NEXT: daddiu $sp, $sp, -16
// CHECK-NEXT: sd $fp, 8($sp) # 8-byte Folded Spill
// CHECK-NEXT: beqz $4, .LBB0_2
// CHECK-NEXT: move $fp, $sp
// CHECK-NEXT: # %bb.1: # %if.then
// CHECK-NEXT: addiu $1, $5, 4
// CHECK-NEXT: dsll $1, $1, 2
// CHECK-NEXT: cincoffset $c3, $c3, $1
// CHECK-NEXT: .LBB0_2: # %if.end
// CHECK-NEXT: move $sp, $fp
// CHECK-NEXT: ld $fp, 8($sp) # 8-byte Folded Reload
// CHECK-NEXT: jr $ra
// CHECK-NEXT: daddiu $sp, $sp, 16
39 changes: 39 additions & 0 deletions llvm/test/CodeGen/Mips/cheri/bad-code-gen-issue-292.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %cheri_clang -v -S -o - -O2 %s -mllvm -print-before=cheriaddrmodefolder -mllvm -print-after=cheriaddrmodefolder | FileCheck %s
// REQUIRES: asserts
// XFAIL: *

// https://github.com/CTSRD-CHERI/llvm-project/issues/292

// CHECK-LABEL doLoop:
// CHECK-NEXT: daddiu $sp, $sp, -16
// CHECK-NEXT: sd $fp, 8($sp) # 8-byte Folded Spill
// CHECK-NEXT: move $fp, $sp
// CHECK-NEXT: cfromptr $1, $c1, $c0
// CHECK-NEXT: cfromptr $2, $c2, $c0
// CHECK-NEXT: clb $1, $6, 1($c1)
// CHECK-NEXT: csb $1, $6, 1($c2)
// CHECK-NEXT: clb $1, $6, 2($c1)
// CHECK-NEXT: csb $1, $6, 2($c2)
// CHECK-NEXT: move $sp, $fp
// CHECK-NEXT: ld $fp, 8($sp) # 8-byte Folded Reload
// CHECK-NEXT: jr $ra
// CHECK-NEXT: daddiu $sp, $sp, 16
// CHECK-NEXT:

void doLoop(char * in, char * out, int i)
{
char * __capability inLocal = (__cheri_tocap char * __capability)in;
char * __capability outLocal = (__cheri_tocap char * __capability)out;
outLocal[i+1]=inLocal[i+1];
outLocal[i+2]=inLocal[i+2];
}

void doLoop2(char * in, char * out, long i)
{
char * __capability inLocal = (char * __capability)in;
char * __capability outLocal = (char * __capability)out;
do {
outLocal[i]=inLocal[i];
i--;
} while (i>0);
}
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/Mips/cheri/cheri-sandbox-vaargs2.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: %cheri128_purecap_llc -cheri-cap-table-abi=pcrel -O2 -o - %s | FileCheck %s -check-prefixes CHECK,PCREL
; RUN: %cheri128_purecap_llc -cheri-cap-table-abi=legacy -O2 -o - %s | FileCheck %s -check-prefixes CHECK,LEGACY
; RUN: %cheri128_purecap_llc -cheri-cap-table-abi=pcrel -O2 -o - %s | FileCheck %s -check-prefixes PCREL
; RUN: %cheri128_purecap_llc -cheri-cap-table-abi=legacy -O2 -o - %s | FileCheck %s -check-prefixes LEGACY
; ModuleID = 'libxo.i'

%struct.xo_handle_s = type { i8 addrspace(200)* }
Expand All @@ -16,8 +16,8 @@ define void @xo_emit(i8 addrspace(200)* %fmt, ...) {
; CHECK: # %bb.0: # %entry
; Save the incoming varargs in a temporary register:
; PCREL: clcbi [[CAP_FOR_B:\$c[0-9]+]], %captab20(b)($c{{[0-9]+}})
; LEGACY: ld [[ADDR_OF_B:\$[0-9]+]], %got_disp(b)($1)
; LEGACY: ld [[SIZE_OF_B:\$[0-9]+]], %got_disp(.size.b)($1)
; LEGACY: ld [[ADDR_OF_B:\$[0-9]+]], %got_disp(b)($1)
; LEGACY: cfromddc [[TMP:\$c[0-9]+]], [[ADDR_OF_B]]
; LEGACY: csetbounds [[CAP_FOR_B:\$c[0-9]+]], [[TMP]], [[SIZE_OF_B]]
; Now store in the global:
Expand Down

0 comments on commit 28b9f7c

Please sign in to comment.