From 0252f35362f34b2fd7a56c8f55fce5b49b4bf36e Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Fri, 23 Feb 2018 23:49:21 +0000 Subject: bpf: Define instruction patterns for extensions and truncations between i32 to i64 For transformations between i32 and i64, if it is explicit signed extension: - first cast the operand to i64 - then use SLL + SRA to finish the extension. if it is explicit zero extension: - first cast the operand to i64 - then use SLL + SRL to finish the extension. if it is explicit any extension: - just refer to 64-bit register. if it is explicit truncation: - just refer to 32-bit subregister. NOTE: Some of the zero extension sequences might be unnecessary, they will be removed by an peephole pass on MachineInstruction layer. Signed-off-by: Jiong Wang Reviewed-by: Yonghong Song llvm-svn: 325981 --- llvm/lib/Target/BPF/BPFInstrInfo.td | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'llvm/lib/Target/BPF') diff --git a/llvm/lib/Target/BPF/BPFInstrInfo.td b/llvm/lib/Target/BPF/BPFInstrInfo.td index d4f9c488f67..88f774cb11f 100644 --- a/llvm/lib/Target/BPF/BPFInstrInfo.td +++ b/llvm/lib/Target/BPF/BPFInstrInfo.td @@ -583,3 +583,23 @@ def LD_ABS_W : LOAD_ABS; def LD_IND_B : LOAD_IND; def LD_IND_H : LOAD_IND; def LD_IND_W : LOAD_IND; + +let isCodeGenOnly = 1 in { + def MOV_32_64 : ALU_RR; +} + +def : Pat<(i64 (sext GPR32:$src)), + (SRA_ri (SLL_ri (MOV_32_64 GPR32:$src), 32), 32)>; + +def : Pat<(i64 (zext GPR32:$src)), + (SRL_ri (SLL_ri (MOV_32_64 GPR32:$src), 32), 32)>; + +// For i64 -> i32 truncation, use the 32-bit subregister directly. +def : Pat<(i32 (trunc GPR:$src)), + (i32 (EXTRACT_SUBREG GPR:$src, sub_32))>; + +// For i32 -> i64 anyext, we don't care about the high bits. +def : Pat<(i64 (anyext GPR32:$src)), + (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GPR32:$src, sub_32)>; -- cgit v1.2.3