diff options
| author | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2018-12-20 16:39:20 +0000 |
|---|---|---|
| committer | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2018-12-20 16:39:20 +0000 |
| commit | 30c42e2ab6893802c2346873f095904df0cbca9a (patch) | |
| tree | c4bfc83189ffa9be25642445a9b716b987052170 /llvm/lib/Target | |
| parent | d363f0842627cba6bbd0f719bfa3894c4ffcbf96 (diff) | |
| download | bcm5719-llvm-30c42e2ab6893802c2346873f095904df0cbca9a.tar.gz bcm5719-llvm-30c42e2ab6893802c2346873f095904df0cbca9a.zip | |
[Hexagon] Add patterns for funnel shifts
llvm-svn: 349770
Diffstat (limited to 'llvm/lib/Target')
| -rw-r--r-- | llvm/lib/Target/Hexagon/HexagonISelLowering.cpp | 11 | ||||
| -rw-r--r-- | llvm/lib/Target/Hexagon/HexagonPatterns.td | 88 |
2 files changed, 96 insertions, 3 deletions
diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp index b5be507bb97..fffacffa622 100644 --- a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -1359,6 +1359,11 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM, setOperationAction(ISD::BSWAP, MVT::i32, Legal); setOperationAction(ISD::BSWAP, MVT::i64, Legal); + setOperationAction(ISD::FSHL, MVT::i32, Legal); + setOperationAction(ISD::FSHL, MVT::i64, Legal); + setOperationAction(ISD::FSHR, MVT::i32, Legal); + setOperationAction(ISD::FSHR, MVT::i64, Legal); + for (unsigned IntExpOp : {ISD::SDIV, ISD::UDIV, ISD::SREM, ISD::UREM, ISD::SDIVREM, ISD::UDIVREM, ISD::ROTL, ISD::ROTR, @@ -1538,8 +1543,10 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM, // Subtarget-specific operation actions. // if (Subtarget.hasV60Ops()) { - setOperationAction(ISD::ROTL, MVT::i32, Custom); - setOperationAction(ISD::ROTL, MVT::i64, Custom); + setOperationAction(ISD::ROTL, MVT::i32, Legal); + setOperationAction(ISD::ROTL, MVT::i64, Legal); + setOperationAction(ISD::ROTR, MVT::i32, Legal); + setOperationAction(ISD::ROTR, MVT::i64, Legal); } if (Subtarget.hasV66Ops()) { setOperationAction(ISD::FADD, MVT::f64, Legal); diff --git a/llvm/lib/Target/Hexagon/HexagonPatterns.td b/llvm/lib/Target/Hexagon/HexagonPatterns.td index 311b5a702d5..89177564057 100644 --- a/llvm/lib/Target/Hexagon/HexagonPatterns.td +++ b/llvm/lib/Target/Hexagon/HexagonPatterns.td @@ -177,6 +177,11 @@ def UDEC32: SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(V-32, SDLoc(N), MVT::i32); }]>; +class Subi<int From>: SDNodeXForm<imm, + "int32_t V = " # From # " - N->getSExtValue();" # + "return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);" +>; + def Log2_32: SDNodeXForm<imm, [{ uint32_t V = N->getZExtValue(); return CurDAG->getTargetConstant(Log2_32(V), SDLoc(N), MVT::i32); @@ -995,10 +1000,90 @@ def: OpR_RR_pat<S2_asr_r_p, Sra, i64, I64, I32>; def: OpR_RR_pat<S2_lsr_r_p, Srl, i64, I64, I32>; def: OpR_RR_pat<S2_asl_r_p, Shl, i64, I64, I32>; -let Predicates = [HasV60] in { +// Funnel shifts. +def IsMul8_U3: PatLeaf<(i32 imm), [{ + uint64_t V = N->getZExtValue(); + return V % 8 == 0 && isUInt<3>(V / 8); +}]>; + +def Divu8: SDNodeXForm<imm, [{ + return CurDAG->getTargetConstant(N->getZExtValue() / 8, SDLoc(N), MVT::i32); +}]>; + +// Funnel shift-left. +def FShl32i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S), + (HiReg (S2_asl_i_p (Combinew $Rs, $Rt), $S))>; +def FShl32r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru), + (HiReg (S2_asl_r_p (Combinew $Rs, $Rt), $Ru))>; + +def FShl64i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S), + (S2_lsr_i_p_or (S2_asl_i_p $Rt, $S), $Rs, (Subi<64> $S))>; +def FShl64r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru), + (S2_lsr_r_p_or (S2_asl_r_p $Rt, $Ru), $Rs, (A2_subri 64, $Ru))>; + +// Combined SDNodeXForm: (Divu8 (Subi<64> $S)) +def Divu64_8: SDNodeXForm<imm, [{ + return CurDAG->getTargetConstant((64 - N->getSExtValue()) / 8, + SDLoc(N), MVT::i32); +}]>; + +// Special cases: +let AddedComplexity = 100 in { + def: Pat<(fshl I32:$Rs, I32:$Rt, (i32 16)), + (A2_combine_hl I32:$Rs, I32:$Rt)>; + def: Pat<(fshl I64:$Rs, I64:$Rt, IsMul8_U3:$S), + (S2_valignib I64:$Rs, I64:$Rt, (Divu64_8 $S))>; +} + +let Predicates = [HasV60], AddedComplexity = 50 in { def: OpR_RI_pat<S6_rol_i_r, Rol, i32, I32, u5_0ImmPred>; def: OpR_RI_pat<S6_rol_i_p, Rol, i64, I64, u6_0ImmPred>; } +let AddedComplexity = 30 in { + def: Pat<(rotl I32:$Rs, u5_0ImmPred:$S), (FShl32i $Rs, $Rs, imm:$S)>; + def: Pat<(rotl I64:$Rs, u6_0ImmPred:$S), (FShl64i $Rs, $Rs, imm:$S)>; + def: Pat<(fshl I32:$Rs, I32:$Rt, u5_0ImmPred:$S), (FShl32i $Rs, $Rt, imm:$S)>; + def: Pat<(fshl I64:$Rs, I64:$Rt, u6_0ImmPred:$S), (FShl64i $Rs, $Rt, imm:$S)>; +} +def: Pat<(rotl I32:$Rs, I32:$Rt), (FShl32r $Rs, $Rs, $Rt)>; +def: Pat<(rotl I64:$Rs, I32:$Rt), (FShl64r $Rs, $Rs, $Rt)>; +def: Pat<(fshl I32:$Rs, I32:$Rt, I32:$Ru), (FShl32r $Rs, $Rt, $Ru)>; +def: Pat<(fshl I64:$Rs, I64:$Rt, I32:$Ru), (FShl64r $Rs, $Rt, $Ru)>; + +// Funnel shift-right. +def FShr32i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S), + (LoReg (S2_lsr_i_p (Combinew $Rs, $Rt), $S))>; +def FShr32r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru), + (LoReg (S2_lsr_r_p (Combinew $Rs, $Rt), $Ru))>; + +def FShr64i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S), + (S2_asl_i_p_or (S2_lsr_i_p $Rt, $S), $Rs, (Subi<64> $S))>; +def FShr64r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru), + (S2_asl_r_p_or (S2_lsr_r_p $Rt, $Ru), $Rs, (A2_subri 64, $Ru))>; + +// Special cases: +let AddedComplexity = 100 in { + def: Pat<(fshr I32:$Rs, I32:$Rt, (i32 16)), + (A2_combine_hl I32:$Rs, I32:$Rt)>; + def: Pat<(fshr I64:$Rs, I64:$Rt, IsMul8_U3:$S), + (S2_valignib I64:$Rs, I64:$Rt, (Divu8 $S))>; +} + +let Predicates = [HasV60], AddedComplexity = 50 in { + def: Pat<(rotr I32:$Rs, u5_0ImmPred:$S), (S6_rol_i_r I32:$Rs, (Subi<32> $S))>; + def: Pat<(rotr I64:$Rs, u6_0ImmPred:$S), (S6_rol_i_p I64:$Rs, (Subi<64> $S))>; +} +let AddedComplexity = 30 in { + def: Pat<(rotr I32:$Rs, u5_0ImmPred:$S), (FShr32i $Rs, $Rs, imm:$S)>; + def: Pat<(rotr I64:$Rs, u6_0ImmPred:$S), (FShr64i $Rs, $Rs, imm:$S)>; + def: Pat<(fshr I32:$Rs, I32:$Rt, u5_0ImmPred:$S), (FShr32i $Rs, $Rt, imm:$S)>; + def: Pat<(fshr I64:$Rs, I64:$Rt, u6_0ImmPred:$S), (FShr64i $Rs, $Rt, imm:$S)>; +} +def: Pat<(rotr I32:$Rs, I32:$Rt), (FShr32r $Rs, $Rs, $Rt)>; +def: Pat<(rotr I64:$Rs, I32:$Rt), (FShr64r $Rs, $Rs, $Rt)>; +def: Pat<(fshr I32:$Rs, I32:$Rt, I32:$Ru), (FShr32r $Rs, $Rt, $Ru)>; +def: Pat<(fshr I64:$Rs, I64:$Rt, I32:$Ru), (FShr64r $Rs, $Rt, $Ru)>; + def: Pat<(sra (add (sra I32:$Rs, u5_0ImmPred:$u5), 1), (i32 1)), (S2_asr_i_r_rnd I32:$Rs, imm:$u5)>; @@ -1183,6 +1268,7 @@ def: Pat<(HexagonVASL V2I16:$Rs, I32:$Rt), def: Pat<(HexagonVLSR V2I16:$Rs, I32:$Rt), (LoReg (S2_lsr_i_vh (ToAext64 $Rs), I32:$Rt))>; + // --(9) Arithmetic/bitwise ---------------------------------------------- // |

