Skip to content

Commit e2102e7

Browse files
committed
[llvm][Mips] Bail on underaligned loads/stores in FastISel.
1 parent 2579b41 commit e2102e7

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

llvm/lib/Target/Mips/MipsFastISel.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,38 +881,50 @@ bool MipsFastISel::selectLogicalOp(const Instruction *I) {
881881
}
882882

883883
bool MipsFastISel::selectLoad(const Instruction *I) {
884+
const LoadInst *LI = cast<LoadInst>(I);
885+
884886
// Atomic loads need special handling.
885-
if (cast<LoadInst>(I)->isAtomic())
887+
if (LI->isAtomic())
886888
return false;
887889

888890
// Verify we have a legal type before going any further.
889891
MVT VT;
890-
if (!isLoadTypeLegal(I->getType(), VT))
892+
if (!isLoadTypeLegal(LI->getType(), VT))
893+
return false;
894+
895+
// Underaligned loads need special handling.
896+
if (LI->getAlign() < VT.getFixedSizeInBits() / 8)
891897
return false;
892898

893899
// See if we can handle this address.
894900
Address Addr;
895-
if (!computeAddress(I->getOperand(0), Addr))
901+
if (!computeAddress(LI->getOperand(0), Addr))
896902
return false;
897903

898904
unsigned ResultReg;
899905
if (!emitLoad(VT, ResultReg, Addr))
900906
return false;
901-
updateValueMap(I, ResultReg);
907+
updateValueMap(LI, ResultReg);
902908
return true;
903909
}
904910

905911
bool MipsFastISel::selectStore(const Instruction *I) {
906-
Value *Op0 = I->getOperand(0);
912+
const StoreInst *SI = cast<StoreInst>(I);
913+
914+
Value *Op0 = SI->getOperand(0);
907915
unsigned SrcReg = 0;
908916

909917
// Atomic stores need special handling.
910-
if (cast<StoreInst>(I)->isAtomic())
918+
if (SI->isAtomic())
911919
return false;
912920

913921
// Verify we have a legal type before going any further.
914922
MVT VT;
915-
if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
923+
if (!isLoadTypeLegal(SI->getOperand(0)->getType(), VT))
924+
return false;
925+
926+
// Underaligned stores need special handling.
927+
if (SI->getAlign() < VT.getFixedSizeInBits() / 8)
916928
return false;
917929

918930
// Get the value to be stored into a register.
@@ -922,7 +934,7 @@ bool MipsFastISel::selectStore(const Instruction *I) {
922934

923935
// See if we can handle this address.
924936
Address Addr;
925-
if (!computeAddress(I->getOperand(1), Addr))
937+
if (!computeAddress(SI->getOperand(1), Addr))
926938
return false;
927939

928940
if (!emitStore(VT, SrcReg, Addr))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llc < %s -march mips -fast-isel -relocation-model pic | FileCheck %s -check-prefixes=MIPS
2+
3+
@var = external global i32, align 1
4+
5+
; FastISel should bail on the underaligned load and store.
6+
define dso_local ccc i32 @__start() {
7+
; MIPS: lw $1, %got(var)($1)
8+
; MIPS-NEXT: lwl $2, 0($1)
9+
; MIPS-NEXT: lwr $2, 3($1)
10+
%1 = load i32, ptr @var, align 1
11+
; MIPS: addiu $3, $zero, 42
12+
; MIPS-NEXT: swl $3, 0($1)
13+
; MIPS-NEXT: jr $ra
14+
; MIPS-NEXT: swr $3, 3($1)
15+
store i32 42, ptr @var, align 1
16+
ret i32 %1
17+
}

0 commit comments

Comments
 (0)