diff --git a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp index 35039cefb59e..15b7df209ef8 100644 --- a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp +++ b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp @@ -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."); diff --git a/llvm/test/CodeGen/Mips/cheri/bad-branch-delay-slot-usage-issue-290.c b/llvm/test/CodeGen/Mips/cheri/bad-branch-delay-slot-usage-issue-290.c new file mode 100644 index 000000000000..c54184ceb1b2 --- /dev/null +++ b/llvm/test/CodeGen/Mips/cheri/bad-branch-delay-slot-usage-issue-290.c @@ -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 diff --git a/llvm/test/CodeGen/Mips/cheri/bad-code-gen-issue-292.c b/llvm/test/CodeGen/Mips/cheri/bad-code-gen-issue-292.c new file mode 100644 index 000000000000..a064299908a7 --- /dev/null +++ b/llvm/test/CodeGen/Mips/cheri/bad-code-gen-issue-292.c @@ -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); +} diff --git a/llvm/test/CodeGen/Mips/cheri/cheri-sandbox-vaargs2.ll b/llvm/test/CodeGen/Mips/cheri/cheri-sandbox-vaargs2.ll index a6656b39c557..fd4f99408ead 100644 --- a/llvm/test/CodeGen/Mips/cheri/cheri-sandbox-vaargs2.ll +++ b/llvm/test/CodeGen/Mips/cheri/cheri-sandbox-vaargs2.ll @@ -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)* } @@ -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: