1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

Correct compatibility with the GNU Assembler's handling of comparison ops

GAS returns -1 for a comparison operator if the result is true and 0 if false.

  https://www.sourceware.org/binutils/docs-2.12/as.info/Infix-Ops.html#Infix%20Ops

llvm-svn: 332215
This commit is contained in:
Bill Wendling 2018-05-14 05:25:36 +00:00
parent 14ee840734
commit 77a2814a9a
4 changed files with 41 additions and 13 deletions

View File

@ -74,7 +74,10 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
case MCUnaryExpr::Not: OS << '~'; break;
case MCUnaryExpr::Plus: OS << '+'; break;
}
bool Binary = UE.getSubExpr()->getKind() == MCExpr::Binary;
if (Binary) OS << "(";
UE.getSubExpr()->print(OS, MAI);
if (Binary) OS << ")";
return;
}
@ -756,7 +759,8 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
// Apple as.
int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
int64_t Result = 0;
switch (ABE->getOpcode()) {
auto Op = ABE->getOpcode();
switch (Op) {
case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
case MCBinaryExpr::Add: Result = LHS + RHS; break;
case MCBinaryExpr::And: Result = LHS & RHS; break;
@ -791,7 +795,21 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
case MCBinaryExpr::Xor: Result = LHS ^ RHS; break;
}
Res = MCValue::get(Result);
switch (Op) {
default:
Res = MCValue::get(Result);
break;
case MCBinaryExpr::EQ:
case MCBinaryExpr::GT:
case MCBinaryExpr::GTE:
case MCBinaryExpr::LT:
case MCBinaryExpr::LTE:
case MCBinaryExpr::NE:
// A comparison operator returns a -1 if true and 0 if false.
Res = MCValue::get(Result ? -1 : 0);
break;
}
return true;
}
}

View File

@ -32,7 +32,7 @@ concat <simple>,<Check>,<0>
# Test #3:
# The altmacro cannot affect the regular less/greater behavior.
# CHECK: addl $1, %eax
# CHECK: addl $-1, %eax
# CHECK: addl $0, %eax
.macro fun3 arg1 arg2

View File

@ -11,11 +11,21 @@ TEST1:
.space 2, 3
# CHECK: TEST2:
# CHECK: .space 1,3
TEST2:
.space -(2 > 0), 3
# CHECK: TEST3:
# CHECK: .space 1
TEST2:
TEST3:
.skip 1
# CHECK: TEST3
# CHECK: TEST4
# CHECK: .space TEST0-TEST1
TEST3:
.space TEST0 - TEST1
TEST4:
.skip TEST0 - TEST1
# CHECK: TEST5
# CHECK: .space -((TEST0-TEST1)>0)
TEST5:
.skip -((TEST0 - TEST1) > 0)

View File

@ -21,12 +21,12 @@ k:
check_expr 1 & 3, 1
check_expr 4 / 2, 2
check_expr 4 / -2, -2
check_expr 1 == 1, 1
check_expr 1 == 1, -1
check_expr 1 == 0, 0
check_expr 1 > 0, 1
check_expr 1 >= 1, 1
check_expr 1 < 2, 1
check_expr 1 <= 1, 1
check_expr 1 > 0, -1
check_expr 1 >= 1, -1
check_expr 1 < 2, -1
check_expr 1 <= 1, -1
check_expr 4 % 3, 1
check_expr 2 * 2, 4
check_expr 2 != 2, 0
@ -43,7 +43,7 @@ k:
check_expr 1 || 2, 1
check_expr 0 || 1, 1
check_expr 0 || 0, 0
check_expr 1 + 2 < 3 + 4, 1
check_expr 1 + 2 < 3 + 4, -1
check_expr 1 << 8 - 1, 128
check_expr 3 * 9 - 2 * 9 + 1, 10