Chromium Code Reviews

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 1024253003: Subzero: Don't use key SSE instructions on potentially unaligned loads. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Push the legalization into the switch statement for better precision Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « src/IceInstX8632.h ('k') | tests_lit/llvm2ice_tests/address-mode-opt.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the TargetLoweringX8632 class, which 10 // This file implements the TargetLoweringX8632 class, which
(...skipping 1357 matching lines...)
1368 case InstArithmetic::Fsub: 1368 case InstArithmetic::Fsub:
1369 case InstArithmetic::Fmul: 1369 case InstArithmetic::Fmul:
1370 case InstArithmetic::Fdiv: 1370 case InstArithmetic::Fdiv:
1371 case InstArithmetic::Frem: 1371 case InstArithmetic::Frem:
1372 llvm_unreachable("FP instruction with i64 type"); 1372 llvm_unreachable("FP instruction with i64 type");
1373 break; 1373 break;
1374 } 1374 }
1375 } else if (isVectorType(Dest->getType())) { 1375 } else if (isVectorType(Dest->getType())) {
1376 // TODO: Trap on integer divide and integer modulo by zero. 1376 // TODO: Trap on integer divide and integer modulo by zero.
1377 // See: https://code.google.com/p/nativeclient/issues/detail?id=3899 1377 // See: https://code.google.com/p/nativeclient/issues/detail?id=3899
1378 if (llvm::isa<OperandX8632Mem>(Src1))
1379 Src1 = legalizeToVar(Src1);
1378 switch (Inst->getOp()) { 1380 switch (Inst->getOp()) {
1379 case InstArithmetic::_num: 1381 case InstArithmetic::_num:
1380 llvm_unreachable("Unknown arithmetic operator"); 1382 llvm_unreachable("Unknown arithmetic operator");
1381 break; 1383 break;
1382 case InstArithmetic::Add: { 1384 case InstArithmetic::Add: {
1383 Variable *T = makeReg(Dest->getType()); 1385 Variable *T = makeReg(Dest->getType());
1384 _movp(T, Src0); 1386 _movp(T, Src0);
1385 _padd(T, Src1); 1387 _padd(T, Src1);
1386 _movp(Dest, T); 1388 _movp(Dest, T);
1387 } break; 1389 } break;
(...skipping 695 matching lines...)
2083 Variable *T = makeReg(Dest->getType()); 2085 Variable *T = makeReg(Dest->getType());
2084 _cvt(T, Src0RM, InstX8632Cvt::Float2float); 2086 _cvt(T, Src0RM, InstX8632Cvt::Float2float);
2085 _mov(Dest, T); 2087 _mov(Dest, T);
2086 break; 2088 break;
2087 } 2089 }
2088 case InstCast::Fptosi: 2090 case InstCast::Fptosi:
2089 if (isVectorType(Dest->getType())) { 2091 if (isVectorType(Dest->getType())) {
2090 assert(Dest->getType() == IceType_v4i32 && 2092 assert(Dest->getType() == IceType_v4i32 &&
2091 Inst->getSrc(0)->getType() == IceType_v4f32); 2093 Inst->getSrc(0)->getType() == IceType_v4f32);
2092 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); 2094 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem);
2095 if (llvm::isa<OperandX8632Mem>(Src0RM))
2096 Src0RM = legalizeToVar(Src0RM);
2093 Variable *T = makeReg(Dest->getType()); 2097 Variable *T = makeReg(Dest->getType());
2094 _cvt(T, Src0RM, InstX8632Cvt::Tps2dq); 2098 _cvt(T, Src0RM, InstX8632Cvt::Tps2dq);
2095 _movp(Dest, T); 2099 _movp(Dest, T);
2096 } else if (Dest->getType() == IceType_i64) { 2100 } else if (Dest->getType() == IceType_i64) {
2097 // Use a helper for converting floating-point values to 64-bit 2101 // Use a helper for converting floating-point values to 64-bit
2098 // integers. SSE2 appears to have no way to convert from xmm 2102 // integers. SSE2 appears to have no way to convert from xmm
2099 // registers to something like the edx:eax register pair, and 2103 // registers to something like the edx:eax register pair, and
2100 // gcc and clang both want to use x87 instructions complete with 2104 // gcc and clang both want to use x87 instructions complete with
2101 // temporary manipulation of the status word. This helper is 2105 // temporary manipulation of the status word. This helper is
2102 // not needed for x86-64. 2106 // not needed for x86-64.
(...skipping 55 matching lines...)
2158 if (Dest->getType() == IceType_i1) 2162 if (Dest->getType() == IceType_i1)
2159 _and(T_2, Ctx->getConstantInt1(1)); 2163 _and(T_2, Ctx->getConstantInt1(1));
2160 _mov(Dest, T_2); 2164 _mov(Dest, T_2);
2161 } 2165 }
2162 break; 2166 break;
2163 case InstCast::Sitofp: 2167 case InstCast::Sitofp:
2164 if (isVectorType(Dest->getType())) { 2168 if (isVectorType(Dest->getType())) {
2165 assert(Dest->getType() == IceType_v4f32 && 2169 assert(Dest->getType() == IceType_v4f32 &&
2166 Inst->getSrc(0)->getType() == IceType_v4i32); 2170 Inst->getSrc(0)->getType() == IceType_v4i32);
2167 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); 2171 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem);
2172 if (llvm::isa<OperandX8632Mem>(Src0RM))
2173 Src0RM = legalizeToVar(Src0RM);
2168 Variable *T = makeReg(Dest->getType()); 2174 Variable *T = makeReg(Dest->getType());
2169 _cvt(T, Src0RM, InstX8632Cvt::Dq2ps); 2175 _cvt(T, Src0RM, InstX8632Cvt::Dq2ps);
2170 _movp(Dest, T); 2176 _movp(Dest, T);
2171 } else if (Inst->getSrc(0)->getType() == IceType_i64) { 2177 } else if (Inst->getSrc(0)->getType() == IceType_i64) {
2172 // Use a helper for x86-32. 2178 // Use a helper for x86-32.
2173 const SizeT MaxSrcs = 1; 2179 const SizeT MaxSrcs = 1;
2174 Type DestType = Dest->getType(); 2180 Type DestType = Dest->getType();
2175 InstCall *Call = 2181 InstCall *Call =
2176 makeHelperCall(isFloat32Asserting32Or64(DestType) ? H_sitofp_i64_f32 2182 makeHelperCall(isFloat32Asserting32Or64(DestType) ? H_sitofp_i64_f32
2177 : H_sitofp_i64_f64, 2183 : H_sitofp_i64_f64,
(...skipping 287 matching lines...)
2465 Variable *T = nullptr; 2471 Variable *T = nullptr;
2466 2472
2467 if (Condition == InstFcmp::True) { 2473 if (Condition == InstFcmp::True) {
2468 // makeVectorOfOnes() requires an integer vector type. 2474 // makeVectorOfOnes() requires an integer vector type.
2469 T = makeVectorOfMinusOnes(IceType_v4i32); 2475 T = makeVectorOfMinusOnes(IceType_v4i32);
2470 } else if (Condition == InstFcmp::False) { 2476 } else if (Condition == InstFcmp::False) {
2471 T = makeVectorOfZeros(Dest->getType()); 2477 T = makeVectorOfZeros(Dest->getType());
2472 } else { 2478 } else {
2473 Operand *Src0RM = legalize(Src0, Legal_Reg | Legal_Mem); 2479 Operand *Src0RM = legalize(Src0, Legal_Reg | Legal_Mem);
2474 Operand *Src1RM = legalize(Src1, Legal_Reg | Legal_Mem); 2480 Operand *Src1RM = legalize(Src1, Legal_Reg | Legal_Mem);
2481 if (llvm::isa<OperandX8632Mem>(Src1RM))
2482 Src1RM = legalizeToVar(Src1RM);
2475 2483
2476 switch (Condition) { 2484 switch (Condition) {
2477 default: { 2485 default: {
2478 CondX86::CmppsCond Predicate = TableFcmp[Index].Predicate; 2486 CondX86::CmppsCond Predicate = TableFcmp[Index].Predicate;
2479 assert(Predicate != CondX86::Cmpps_Invalid); 2487 assert(Predicate != CondX86::Cmpps_Invalid);
2480 T = makeReg(Src0RM->getType()); 2488 T = makeReg(Src0RM->getType());
2481 _movp(T, Src0RM); 2489 _movp(T, Src0RM);
2482 _cmpps(T, Src1RM, Predicate); 2490 _cmpps(T, Src1RM, Predicate);
2483 } break; 2491 } break;
2484 case InstFcmp::One: { 2492 case InstFcmp::One: {
(...skipping 117 matching lines...)
2602 Src0RM = T0; 2610 Src0RM = T0;
2603 Src1RM = T1; 2611 Src1RM = T1;
2604 } 2612 }
2605 2613
2606 Variable *T = makeReg(Ty); 2614 Variable *T = makeReg(Ty);
2607 switch (Condition) { 2615 switch (Condition) {
2608 default: 2616 default:
2609 llvm_unreachable("unexpected condition"); 2617 llvm_unreachable("unexpected condition");
2610 break; 2618 break;
2611 case InstIcmp::Eq: { 2619 case InstIcmp::Eq: {
2620 if (llvm::isa<OperandX8632Mem>(Src1RM))
2621 Src1RM = legalizeToVar(Src1RM);
2612 _movp(T, Src0RM); 2622 _movp(T, Src0RM);
2613 _pcmpeq(T, Src1RM); 2623 _pcmpeq(T, Src1RM);
2614 } break; 2624 } break;
2615 case InstIcmp::Ne: { 2625 case InstIcmp::Ne: {
2626 if (llvm::isa<OperandX8632Mem>(Src1RM))
2627 Src1RM = legalizeToVar(Src1RM);
2616 _movp(T, Src0RM); 2628 _movp(T, Src0RM);
2617 _pcmpeq(T, Src1RM); 2629 _pcmpeq(T, Src1RM);
2618 Variable *MinusOne = makeVectorOfMinusOnes(Ty); 2630 Variable *MinusOne = makeVectorOfMinusOnes(Ty);
2619 _pxor(T, MinusOne); 2631 _pxor(T, MinusOne);
2620 } break; 2632 } break;
2621 case InstIcmp::Ugt: 2633 case InstIcmp::Ugt:
2622 case InstIcmp::Sgt: { 2634 case InstIcmp::Sgt: {
2635 if (llvm::isa<OperandX8632Mem>(Src1RM))
2636 Src1RM = legalizeToVar(Src1RM);
2623 _movp(T, Src0RM); 2637 _movp(T, Src0RM);
2624 _pcmpgt(T, Src1RM); 2638 _pcmpgt(T, Src1RM);
2625 } break; 2639 } break;
2626 case InstIcmp::Uge: 2640 case InstIcmp::Uge:
2627 case InstIcmp::Sge: { 2641 case InstIcmp::Sge: {
2628 // !(Src1RM > Src0RM) 2642 // !(Src1RM > Src0RM)
2643 if (llvm::isa<OperandX8632Mem>(Src0RM))
2644 Src0RM = legalizeToVar(Src0RM);
2629 _movp(T, Src1RM); 2645 _movp(T, Src1RM);
2630 _pcmpgt(T, Src0RM); 2646 _pcmpgt(T, Src0RM);
2631 Variable *MinusOne = makeVectorOfMinusOnes(Ty); 2647 Variable *MinusOne = makeVectorOfMinusOnes(Ty);
2632 _pxor(T, MinusOne); 2648 _pxor(T, MinusOne);
2633 } break; 2649 } break;
2634 case InstIcmp::Ult: 2650 case InstIcmp::Ult:
2635 case InstIcmp::Slt: { 2651 case InstIcmp::Slt: {
2652 if (llvm::isa<OperandX8632Mem>(Src0RM))
2653 Src0RM = legalizeToVar(Src0RM);
2636 _movp(T, Src1RM); 2654 _movp(T, Src1RM);
2637 _pcmpgt(T, Src0RM); 2655 _pcmpgt(T, Src0RM);
2638 } break; 2656 } break;
2639 case InstIcmp::Ule: 2657 case InstIcmp::Ule:
2640 case InstIcmp::Sle: { 2658 case InstIcmp::Sle: {
2641 // !(Src0RM > Src1RM) 2659 // !(Src0RM > Src1RM)
2660 if (llvm::isa<OperandX8632Mem>(Src1RM))
2661 Src1RM = legalizeToVar(Src1RM);
2642 _movp(T, Src0RM); 2662 _movp(T, Src0RM);
2643 _pcmpgt(T, Src1RM); 2663 _pcmpgt(T, Src1RM);
2644 Variable *MinusOne = makeVectorOfMinusOnes(Ty); 2664 Variable *MinusOne = makeVectorOfMinusOnes(Ty);
2645 _pxor(T, MinusOne); 2665 _pxor(T, MinusOne);
2646 } break; 2666 } break;
2647 } 2667 }
2648 2668
2649 _movp(Dest, T); 2669 _movp(Dest, T);
2650 eliminateNextVectorSextInstruction(Dest); 2670 eliminateNextVectorSextInstruction(Dest);
2651 return; 2671 return;
(...skipping 433 matching lines...)
3085 SecondVal); 3105 SecondVal);
3086 return; 3106 return;
3087 } 3107 }
3088 case Intrinsics::Fabs: { 3108 case Intrinsics::Fabs: {
3089 Operand *Src = legalize(Instr->getArg(0)); 3109 Operand *Src = legalize(Instr->getArg(0));
3090 Type Ty = Src->getType(); 3110 Type Ty = Src->getType();
3091 Variable *Dest = Instr->getDest(); 3111 Variable *Dest = Instr->getDest();
3092 Variable *T = makeVectorOfFabsMask(Ty); 3112 Variable *T = makeVectorOfFabsMask(Ty);
3093 // The pand instruction operates on an m128 memory operand, so if 3113 // The pand instruction operates on an m128 memory operand, so if
3094 // Src is an f32 or f64, we need to make sure it's in a register. 3114 // Src is an f32 or f64, we need to make sure it's in a register.
3095 if (!isVectorType(Ty)) 3115 if (isVectorType(Ty)) {
3116 if (llvm::isa<OperandX8632Mem>(Src))
3117 Src = legalizeToVar(Src);
3118 } else {
3096 Src = legalizeToVar(Src); 3119 Src = legalizeToVar(Src);
3120 }
3097 _pand(T, Src); 3121 _pand(T, Src);
3098 if (isVectorType(Ty)) 3122 if (isVectorType(Ty))
3099 _movp(Dest, T); 3123 _movp(Dest, T);
3100 else 3124 else
3101 _mov(Dest, T); 3125 _mov(Dest, T);
3102 return; 3126 return;
3103 } 3127 }
3104 case Intrinsics::Longjmp: { 3128 case Intrinsics::Longjmp: {
3105 InstCall *Call = makeHelperCall(H_call_longjmp, nullptr, 2); 3129 InstCall *Call = makeHelperCall(H_call_longjmp, nullptr, 2);
3106 Call->addArg(Instr->getArg(0)); 3130 Call->addArg(Instr->getArg(0));
(...skipping 1740 matching lines...)
4847 case FT_Asm: 4871 case FT_Asm:
4848 case FT_Iasm: { 4872 case FT_Iasm: {
4849 OstreamLocker L(Ctx); 4873 OstreamLocker L(Ctx);
4850 emitConstantPool<PoolTypeConverter<float>>(Ctx); 4874 emitConstantPool<PoolTypeConverter<float>>(Ctx);
4851 emitConstantPool<PoolTypeConverter<double>>(Ctx); 4875 emitConstantPool<PoolTypeConverter<double>>(Ctx);
4852 } break; 4876 } break;
4853 } 4877 }
4854 } 4878 }
4855 4879
4856 } // end of namespace Ice 4880 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceInstX8632.h ('k') | tests_lit/llvm2ice_tests/address-mode-opt.ll » ('j') | no next file with comments »

Powered by Google App Engine