From d49ffe8284457953db68db063b527ee9c346b67a Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Fri, 29 Apr 2011 14:18:15 +0000 Subject: [PATCH] Teach Thumb2 isel to fold and->rotr ==> ROR. Generalization of Nate Begeman's patch! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130502 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMInstrThumb2.td | 9 +++++++++ test/CodeGen/Thumb2/thumb2-ror.ll | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Target/ARM/ARMInstrThumb2.td b/lib/Target/ARM/ARMInstrThumb2.td index 165ae7e20af..5cfb7cd3ec8 100644 --- a/lib/Target/ARM/ARMInstrThumb2.td +++ b/lib/Target/ARM/ARMInstrThumb2.td @@ -84,6 +84,11 @@ def imm0_255_not : PatLeaf<(i32 imm), [{ return (uint32_t)(~N->getZExtValue()) < 255; }], imm_comp_XFORM>; +def lo5AllOne : PatLeaf<(i32 imm), [{ + // Returns true if all low 5-bits are 1. + return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL; +}]>; + // Define Thumb2 specific addressing modes. // t2addrmode_imm12 := reg + imm12 @@ -2023,6 +2028,10 @@ defm t2LSR : T2I_sh_ir<0b01, "lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>; defm t2ASR : T2I_sh_ir<0b10, "asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>; defm t2ROR : T2I_sh_ir<0b11, "ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>; +// (rotr x, (and y, 0x...1f)) ==> (ROR x, y) +def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)), + (t2RORrr rGPR:$lhs, rGPR:$rhs)>; + let Uses = [CPSR] in { def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi, "rrx", "\t$Rd, $Rm", diff --git a/test/CodeGen/Thumb2/thumb2-ror.ll b/test/CodeGen/Thumb2/thumb2-ror.ll index c44fdb3ad50..590c333b3d1 100644 --- a/test/CodeGen/Thumb2/thumb2-ror.ll +++ b/test/CodeGen/Thumb2/thumb2-ror.ll @@ -11,11 +11,13 @@ define i32 @f1(i32 %a) { } ; CHECK: f2: +; CHECK-NOT: and ; CHECK: ror define i32 @f2(i32 %v, i32 %nbits) { entry: - %shr = lshr i32 %v, %nbits - %sub = sub i32 32, %nbits + %and = and i32 %nbits, 31 + %shr = lshr i32 %v, %and + %sub = sub i32 32, %and %shl = shl i32 %v, %sub %or = or i32 %shl, %shr ret i32 %or -- 2.34.1