]> granicus.if.org Git - llvm/commitdiff
[ARM] Mark 255 and 65535 as cheap for Thumb1 "And"
authorDavid Green <david.green@arm.com>
Mon, 4 Feb 2019 11:58:48 +0000 (11:58 +0000)
committerDavid Green <david.green@arm.com>
Mon, 4 Feb 2019 11:58:48 +0000 (11:58 +0000)
This prevents Constant Hoisting from pulling the constant out of the block,
allowing us to still produce LDRH/UXTH nodes. LDRB/UXTB (255) is already cheap
by the default getIntImmCost, but I've added it for clarity.

Differential Revision: https://reviews.llvm.org/D57671

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353040 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMTargetTransformInfo.cpp
test/CodeGen/Thumb/uxth.ll

index 6ddf75401dcc6930fac9054c57a67f7fa0b25a85..1d1d92c99a33f4f8da9fc02cc65771b0a9b91419 100644 (file)
@@ -106,9 +106,13 @@ int ARMTTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
       Idx == 1)
     return 0;
 
-  if (Opcode == Instruction::And)
-      // Conversion to BIC is free, and means we can use ~Imm instead.
-      return std::min(getIntImmCost(Imm, Ty), getIntImmCost(~Imm, Ty));
+  if (Opcode == Instruction::And) {
+    // UXTB/UXTH
+    if (Imm == 255 || Imm == 65535)
+      return 0;
+    // Conversion to BIC is free, and means we can use ~Imm instead.
+    return std::min(getIntImmCost(Imm, Ty), getIntImmCost(~Imm, Ty));
+  }
 
   if (Opcode == Instruction::Add)
     // Conversion to SUB is free, and means we can use -Imm instead.
index 11514d80899c3897ec7e5e8ee0e20369dcc22f09..e1e5117b394e7ed7a65a68d721b207e10c0ea0ac 100644 (file)
@@ -68,24 +68,18 @@ for.cond.cleanup:
 
 define void @uxth_loop_2(i32* %a, i32 %n) {
 ; V6M-LABEL: uxth_loop_2:
-; V6M:         .save {r4, r5, r7, lr}
-; V6M-NEXT:    push {r4, r5, r7, lr}
-; V6M-NEXT:    movs r3, #0
-; V6M-NEXT:    ldr r2, .LCPI5_0
+; V6M:         .save {r4, lr}
+; V6M-NEXT:    push {r4, lr}
+; V6M-NEXT:    movs r2, #0
 ; V6M-NEXT:  .LBB5_1:
-; V6M-NEXT:    adds r4, r3, #1
-; V6M-NEXT:    ands r3, r2
-; V6M-NEXT:    ldr r5, [r0]
-; V6M-NEXT:    ands r5, r2
-; V6M-NEXT:    muls r5, r3, r5
-; V6M-NEXT:    stm r0!, {r5}
-; V6M-NEXT:    cmp r1, r4
-; V6M-NEXT:    mov r3, r4
+; V6M-NEXT:    uxth r3, r2
+; V6M-NEXT:    ldrh r4, [r0]
+; V6M-NEXT:    muls r4, r3, r4
+; V6M-NEXT:    stm r0!, {r4}
+; V6M-NEXT:    adds r2, r2, #1
+; V6M-NEXT:    cmp r1, r2
 ; V6M-NEXT:    bne .LBB5_1
-; V6M-NEXT:    pop {r4, r5, r7, pc}
-; V6M-NEXT:    .p2align 2
-; V6M-NEXT:  .LCPI5_0:
-; V6M-NEXT:    .long 65535
+; V6M-NEXT:    pop {r4, pc}
 entry:
   br label %for.body