Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions llvm/lib/TableGen/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ const Init *BinOpInit::Fold(const Record *CurRec) const {
if (LHSi && RHSi) {
int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
int64_t Result;

switch (getOpcode()) {
default: llvm_unreachable("Bad opcode!");
case ADD: Result = LHSv + RHSv; break;
Expand All @@ -1564,9 +1565,24 @@ const Init *BinOpInit::Fold(const Record *CurRec) const {
case AND: Result = LHSv & RHSv; break;
case OR: Result = LHSv | RHSv; break;
case XOR: Result = LHSv ^ RHSv; break;
case SHL: Result = (uint64_t)LHSv << (uint64_t)RHSv; break;
case SRA: Result = LHSv >> RHSv; break;
case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
case SHL:
if (RHSv < 0 || RHSv >= 64)
PrintFatalError(CurRec->getLoc(),
"Illegal operation: out of bounds shift");
Result = (uint64_t)LHSv << (uint64_t)RHSv;
break;
case SRA:
if (RHSv < 0 || RHSv >= 64)
PrintFatalError(CurRec->getLoc(),
"Illegal operation: out of bounds shift");
Result = LHSv >> (uint64_t)RHSv;
break;
case SRL:
if (RHSv < 0 || RHSv >= 64)
PrintFatalError(CurRec->getLoc(),
"Illegal operation: out of bounds shift");
Result = (uint64_t)LHSv >> (uint64_t)RHSv;
break;
}
return IntInit::get(getRecordKeeper(), Result);
}
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/TableGen/math.td
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
// RUN: not llvm-tblgen -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
// RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
// RUN: not llvm-tblgen -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
// RUN: not llvm-tblgen -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s
// XFAIL: vg_leak

// CHECK: def shifts
Expand Down Expand Up @@ -143,3 +146,18 @@ def v954 : Int<!logtwo(-1)>;
// CHECK: def vneg
// CHECK: Value = -2
def vneg : Int<!sub(v925.Value, 927)>;

#ifdef ERROR5
// ERROR5: error: Illegal operation: out of bounds shift
def vshl_neg : Int<!shl(1, -1)>;
#endif

#ifdef ERROR6
// ERROR6: error: Illegal operation: out of bounds shift
def vsra_large : Int<!sra(1, 64)>;
#endif

#ifdef ERROR7
// ERROR7: error: Illegal operation: out of bounds shift
def vsrl_large : Int<!srl(1, 100)>;
#endif