| Index: src/IceTargetLoweringX8632.cpp
|
| diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
|
| index 7b977585b5c6e910cb6bc8f2e02f4b678c518d15..973a9622ae722ae83472872d73edfc3c25629faf 100644
|
| --- a/src/IceTargetLoweringX8632.cpp
|
| +++ b/src/IceTargetLoweringX8632.cpp
|
| @@ -1513,6 +1513,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| case InstArithmetic::Add:
|
| _mov(T, Src0);
|
| _add(T, Src1);
|
| + if (Dest->getType() == IceType_i1)
|
| + _and(T, Ctx->getConstantInt(IceType_i1, 1));
|
| _mov(Dest, T);
|
| break;
|
| case InstArithmetic::And:
|
| @@ -1533,6 +1535,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| case InstArithmetic::Sub:
|
| _mov(T, Src0);
|
| _sub(T, Src1);
|
| + if (Dest->getType() == IceType_i1)
|
| + _and(T, Ctx->getConstantInt(IceType_i1, 1));
|
| _mov(Dest, T);
|
| break;
|
| case InstArithmetic::Mul:
|
| @@ -1543,7 +1547,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| //
|
| // The 8-bit version of imul only allows the form "imul r/m8"
|
| // where T must be in eax.
|
| - if (Dest->getType() == IceType_i8)
|
| + if (Dest->getType() == IceType_i1 || Dest->getType() == IceType_i8)
|
| _mov(T, Src0, Reg_eax);
|
| else
|
| _mov(T, Src0);
|
| @@ -1555,6 +1559,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| if (!llvm::isa<Constant>(Src1))
|
| Src1 = legalizeToVar(Src1, false, Reg_ecx);
|
| _shl(T, Src1);
|
| + if (Dest->getType() == IceType_i1)
|
| + _and(T, Ctx->getConstantInt(IceType_i1, 1));
|
| _mov(Dest, T);
|
| break;
|
| case InstArithmetic::Lshr:
|
| @@ -1575,7 +1581,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| // div and idiv are the few arithmetic operators that do not allow
|
| // immediates as the operand.
|
| Src1 = legalize(Src1, Legal_Reg | Legal_Mem);
|
| - if (Dest->getType() == IceType_i8) {
|
| + if (Dest->getType() == IceType_i1 || Dest->getType() == IceType_i8) {
|
| Variable *T_ah = NULL;
|
| Constant *Zero = Ctx->getConstantZero(IceType_i8);
|
| _mov(T, Src0, Reg_eax);
|
| @@ -1592,7 +1598,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| break;
|
| case InstArithmetic::Sdiv:
|
| Src1 = legalize(Src1, Legal_Reg | Legal_Mem);
|
| - if (Dest->getType() == IceType_i8) {
|
| + if (Dest->getType() == IceType_i1 || Dest->getType() == IceType_i8) {
|
| _mov(T, Src0, Reg_eax);
|
| _cbwdq(T, T);
|
| _idiv(T, Src1, T);
|
| @@ -1607,7 +1613,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| break;
|
| case InstArithmetic::Urem:
|
| Src1 = legalize(Src1, Legal_Reg | Legal_Mem);
|
| - if (Dest->getType() == IceType_i8) {
|
| + if (Dest->getType() == IceType_i1 || Dest->getType() == IceType_i8) {
|
| Variable *T_ah = NULL;
|
| Constant *Zero = Ctx->getConstantZero(IceType_i8);
|
| _mov(T, Src0, Reg_eax);
|
| @@ -1624,7 +1630,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
|
| break;
|
| case InstArithmetic::Srem:
|
| Src1 = legalize(Src1, Legal_Reg | Legal_Mem);
|
| - if (Dest->getType() == IceType_i8) {
|
| + if (Dest->getType() == IceType_i1 || Dest->getType() == IceType_i8) {
|
| Variable *T_ah = makeReg(IceType_i8, Reg_ah);
|
| _mov(T, Src0, Reg_eax);
|
| _cbwdq(T, T);
|
| @@ -1965,8 +1971,13 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
|
| // dst = t1
|
| size_t DestBits = X86_CHAR_BIT * typeWidthInBytes(Dest->getType());
|
| Constant *ShiftAmount = Ctx->getConstantInt(IceType_i32, DestBits - 1);
|
| - Variable *T = NULL;
|
| - _mov(T, Src0RM);
|
| + Variable *T = makeReg(Dest->getType());
|
| + if (typeWidthInBytes(Dest->getType()) <=
|
| + typeWidthInBytes(Src0RM->getType())) {
|
| + _mov(T, Src0RM);
|
| + } else {
|
| + _movzx(T, Src0RM);
|
| + }
|
| _shl(T, ShiftAmount);
|
| _sar(T, ShiftAmount);
|
| _mov(Dest, T);
|
| @@ -2038,6 +2049,8 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
|
| // t1 = trunc Src0RM; Dest = t1
|
| Variable *T = NULL;
|
| _mov(T, Src0RM);
|
| + if (Dest->getType() == IceType_i1)
|
| + _and(T, Ctx->getConstantInt(IceType_i1, 1));
|
| _mov(Dest, T);
|
| }
|
| break;
|
| @@ -2081,6 +2094,8 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
|
| Variable *T_2 = makeReg(Dest->getType());
|
| _cvt(T_1, Src0RM);
|
| _mov(T_2, T_1); // T_1 and T_2 may have different integer types
|
| + if (Dest->getType() == IceType_i1)
|
| + _and(T_2, Ctx->getConstantInt(IceType_i1, 1));
|
| _mov(Dest, T_2);
|
| T_2->setPreferredRegister(T_1, true);
|
| }
|
| @@ -2116,6 +2131,8 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
|
| Variable *T_2 = makeReg(Dest->getType());
|
| _cvt(T_1, Src0RM);
|
| _mov(T_2, T_1); // T_1 and T_2 may have different integer types
|
| + if (Dest->getType() == IceType_i1)
|
| + _and(T_2, Ctx->getConstantInt(IceType_i1, 1));
|
| _mov(Dest, T_2);
|
| T_2->setPreferredRegister(T_1, true);
|
| }
|
|
|