Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceTargetLoweringX86BaseImpl.h - x86 lowering -*- C++ -*-==// | 1 //===- subzero/src/IceTargetLoweringX86BaseImpl.h - x86 lowering -*- C++ -*-==// |
| 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 /// \file | 10 /// \file |
| (...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2762 eliminateNextVectorSextInstruction(Dest); | 2762 eliminateNextVectorSextInstruction(Dest); |
| 2763 return; | 2763 return; |
| 2764 } | 2764 } |
| 2765 | 2765 |
| 2766 if (!Traits::Is64Bit && Src0->getType() == IceType_i64) { | 2766 if (!Traits::Is64Bit && Src0->getType() == IceType_i64) { |
| 2767 lowerIcmp64(Inst); | 2767 lowerIcmp64(Inst); |
| 2768 return; | 2768 return; |
| 2769 } | 2769 } |
| 2770 | 2770 |
| 2771 // cmp b, c | 2771 // cmp b, c |
| 2772 if (auto *Const = llvm::dyn_cast<ConstantInteger32>(Src1)) { | |
| 2773 Type Ty = Src0->getType(); | |
| 2774 if ((Const->getValue() == 0) && | |
| 2775 (Ty == IceType_i32 || Ty == IceType_i16 || Ty == IceType_i8)) { | |
|
Jim Stichnoth
2015/10/15 00:48:47
Do you need these tests on Ty?
Vector and FP type
sehr
2015/10/15 17:33:45
Removed.
| |
| 2776 Constant *Zero = Ctx->getConstantInt1(0); | |
| 2777 Constant *One = Ctx->getConstantInt1(1); | |
| 2778 InstIcmp::ICond Condition = Inst->getCondition(); | |
| 2779 switch (Condition) { | |
| 2780 default: | |
| 2781 break; | |
| 2782 case InstIcmp::Uge: | |
| 2783 _mov(Dest, One); | |
| 2784 return; | |
| 2785 case InstIcmp::Ult: | |
| 2786 _mov(Dest, Zero); | |
| 2787 return; | |
| 2788 } | |
| 2789 } | |
| 2790 } | |
| 2772 Operand *Src0RM = legalizeSrc0ForCmp(Src0, Src1); | 2791 Operand *Src0RM = legalizeSrc0ForCmp(Src0, Src1); |
| 2773 _cmp(Src0RM, Src1); | 2792 _cmp(Src0RM, Src1); |
| 2774 _setcc(Dest, Traits::getIcmp32Mapping(Inst->getCondition())); | 2793 _setcc(Dest, Traits::getIcmp32Mapping(Inst->getCondition())); |
| 2775 } | 2794 } |
| 2776 | 2795 |
| 2777 template <typename Machine> | 2796 template <typename Machine> |
| 2778 template <typename T> | 2797 template <typename T> |
| 2779 typename std::enable_if<!T::Is64Bit, void>::type | 2798 typename std::enable_if<!T::Is64Bit, void>::type |
| 2780 TargetX86Base<Machine>::lowerIcmp64(const InstIcmp *Inst) { | 2799 TargetX86Base<Machine>::lowerIcmp64(const InstIcmp *Inst) { |
| 2781 // a=icmp cond, b, c ==> cmp b,c; a=1; br cond,L1; FakeUse(a); a=0; L1: | 2800 // a=icmp cond, b, c ==> cmp b,c; a=1; br cond,L1; FakeUse(a); a=0; L1: |
| 2782 Operand *Src0 = legalize(Inst->getSrc(0)); | 2801 Operand *Src0 = legalize(Inst->getSrc(0)); |
| 2783 Operand *Src1 = legalize(Inst->getSrc(1)); | 2802 Operand *Src1 = legalize(Inst->getSrc(1)); |
| 2784 Variable *Dest = Inst->getDest(); | 2803 Variable *Dest = Inst->getDest(); |
| 2785 InstIcmp::ICond Condition = Inst->getCondition(); | 2804 InstIcmp::ICond Condition = Inst->getCondition(); |
| 2786 size_t Index = static_cast<size_t>(Condition); | 2805 size_t Index = static_cast<size_t>(Condition); |
| 2787 assert(Index < Traits::TableIcmp64Size); | 2806 assert(Index < Traits::TableIcmp64Size); |
| 2788 Operand *Src0LoRM = legalize(loOperand(Src0), Legal_Reg | Legal_Mem); | 2807 Constant *Zero = Ctx->getConstantZero(IceType_i32); |
| 2789 Operand *Src0HiRM = legalize(hiOperand(Src0), Legal_Reg | Legal_Mem); | 2808 Constant *One = Ctx->getConstantInt32(1); |
| 2809 Operand *Src0LoRM = nullptr; | |
| 2810 Operand *Src0HiRM = nullptr; | |
| 2811 // Legalize the portions of Src0 that are going to be needed. | |
| 2812 if (llvm::isa<ConstantInteger64>(Src1) && | |
|
Jim Stichnoth
2015/10/15 00:48:47
I don't like isa<> followed by cast<> or dyn_cast<
sehr
2015/10/15 17:33:45
Done.
| |
| 2813 (llvm::dyn_cast<ConstantInteger64>(Src1)->getValue() == 0)) { | |
| 2814 switch (Condition) { | |
| 2815 default: | |
| 2816 llvm_unreachable("unexpected condition"); | |
| 2817 break; | |
| 2818 // These two are not optimized, so we fall through to the general case, | |
| 2819 // which needs the upper and lower halves legalized. | |
| 2820 case InstIcmp::Sgt: | |
| 2821 case InstIcmp::Sle: | |
| 2822 // These four or the high and low half and compare, so they need the | |
|
Jim Stichnoth
2015/10/15 00:48:47
s/or/are/ ?
sehr
2015/10/15 17:33:46
Reworded to avoid the convoluted mis-parse possibl
| |
| 2823 // upper and lower halves legalized. | |
| 2824 case InstIcmp::Eq: | |
| 2825 case InstIcmp::Ule: | |
| 2826 case InstIcmp::Ne: | |
| 2827 case InstIcmp::Ugt: | |
| 2828 Src0LoRM = legalize(loOperand(Src0), Legal_Reg | Legal_Mem); | |
| 2829 // These two test only the high half's sign bit, so they need only | |
| 2830 // the upper half legalized. | |
| 2831 case InstIcmp::Sge: | |
| 2832 case InstIcmp::Slt: | |
| 2833 Src0HiRM = legalize(hiOperand(Src0), Legal_Reg | Legal_Mem); | |
| 2834 break; | |
| 2835 | |
| 2836 // These two move constants and hence need no legalization. | |
| 2837 case InstIcmp::Uge: | |
| 2838 case InstIcmp::Ult: | |
| 2839 break; | |
| 2840 } | |
| 2841 } else { | |
| 2842 Src0LoRM = legalize(loOperand(Src0), Legal_Reg | Legal_Mem); | |
| 2843 Src0HiRM = legalize(hiOperand(Src0), Legal_Reg | Legal_Mem); | |
| 2844 } | |
| 2845 // Optimize the comparisons with zero. | |
| 2846 if (llvm::isa<ConstantInteger64>(Src1) && | |
| 2847 (llvm::dyn_cast<ConstantInteger64>(Src1)->getValue() == 0)) { | |
| 2848 Constant *SignMask = Ctx->getConstantInt32(0x80000000); | |
| 2849 Variable *Temp = nullptr; | |
| 2850 switch (Condition) { | |
| 2851 default: | |
| 2852 llvm_unreachable("unexpected condition"); | |
| 2853 break; | |
| 2854 case InstIcmp::Eq: | |
| 2855 case InstIcmp::Ule: | |
| 2856 _mov(Temp, Src0LoRM); | |
| 2857 _or(Temp, Src0HiRM); | |
| 2858 Context.insert(InstFakeUse::create(Func, Temp)); | |
| 2859 _setcc(Dest, Traits::Cond::Br_e); | |
| 2860 return; | |
| 2861 case InstIcmp::Ne: | |
| 2862 case InstIcmp::Ugt: | |
| 2863 _mov(Temp, Src0LoRM); | |
| 2864 _or(Temp, Src0HiRM); | |
| 2865 Context.insert(InstFakeUse::create(Func, Temp)); | |
| 2866 _setcc(Dest, Traits::Cond::Br_ne); | |
| 2867 return; | |
| 2868 case InstIcmp::Uge: | |
| 2869 _mov(Dest, Ctx->getConstantInt1(1)); | |
| 2870 return; | |
| 2871 case InstIcmp::Ult: | |
| 2872 _mov(Dest, Ctx->getConstantInt1(0)); | |
| 2873 return; | |
| 2874 case InstIcmp::Sgt: | |
| 2875 break; | |
| 2876 case InstIcmp::Sge: | |
| 2877 _test(Src0HiRM, SignMask); | |
| 2878 _setcc(Dest, Traits::Cond::Br_e); | |
| 2879 return; | |
| 2880 case InstIcmp::Slt: | |
| 2881 _test(Src0HiRM, SignMask); | |
| 2882 _setcc(Dest, Traits::Cond::Br_ne); | |
| 2883 return; | |
| 2884 case InstIcmp::Sle: | |
| 2885 break; | |
| 2886 } | |
| 2887 } | |
| 2888 // Handle general compares. | |
| 2790 Operand *Src1LoRI = legalize(loOperand(Src1), Legal_Reg | Legal_Imm); | 2889 Operand *Src1LoRI = legalize(loOperand(Src1), Legal_Reg | Legal_Imm); |
| 2791 Operand *Src1HiRI = legalize(hiOperand(Src1), Legal_Reg | Legal_Imm); | 2890 Operand *Src1HiRI = legalize(hiOperand(Src1), Legal_Reg | Legal_Imm); |
| 2792 Constant *Zero = Ctx->getConstantZero(IceType_i32); | |
| 2793 Constant *One = Ctx->getConstantInt32(1); | |
| 2794 typename Traits::Insts::Label *LabelFalse = | 2891 typename Traits::Insts::Label *LabelFalse = |
| 2795 Traits::Insts::Label::create(Func, this); | 2892 Traits::Insts::Label::create(Func, this); |
| 2796 typename Traits::Insts::Label *LabelTrue = | 2893 typename Traits::Insts::Label *LabelTrue = |
| 2797 Traits::Insts::Label::create(Func, this); | 2894 Traits::Insts::Label::create(Func, this); |
| 2798 _mov(Dest, One); | 2895 _mov(Dest, One); |
| 2799 _cmp(Src0HiRM, Src1HiRI); | 2896 _cmp(Src0HiRM, Src1HiRI); |
| 2800 if (Traits::TableIcmp64[Index].C1 != Traits::Cond::Br_None) | 2897 if (Traits::TableIcmp64[Index].C1 != Traits::Cond::Br_None) |
| 2801 _br(Traits::TableIcmp64[Index].C1, LabelTrue); | 2898 _br(Traits::TableIcmp64[Index].C1, LabelTrue); |
| 2802 if (Traits::TableIcmp64[Index].C2 != Traits::Cond::Br_None) | 2899 if (Traits::TableIcmp64[Index].C2 != Traits::Cond::Br_None) |
| 2803 _br(Traits::TableIcmp64[Index].C2, LabelFalse); | 2900 _br(Traits::TableIcmp64[Index].C2, LabelFalse); |
| (...skipping 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5509 } | 5606 } |
| 5510 // the offset is not eligible for blinding or pooling, return the original | 5607 // the offset is not eligible for blinding or pooling, return the original |
| 5511 // mem operand | 5608 // mem operand |
| 5512 return MemOperand; | 5609 return MemOperand; |
| 5513 } | 5610 } |
| 5514 | 5611 |
| 5515 } // end of namespace X86Internal | 5612 } // end of namespace X86Internal |
| 5516 } // end of namespace Ice | 5613 } // end of namespace Ice |
| 5517 | 5614 |
| 5518 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H | 5615 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASEIMPL_H |
| OLD | NEW |