[PATCH] AArch64: Fold immediate into the immediate field of logical instructions

Akira Hatanaka ahatanak at gmail.com
Thu Oct 2 16:08:22 PDT 2014


llvm currently turns the following code

void foo1(int a, char *p) {
  int t = a & 0xfd;
  *p = t;
}

into these instructions:

movz w8, #253
and w8, w0, w8
strb w8, [x1]

This can be done using just two instructions, since we don't care what the upper 24-bits of the "and" instruction are.

and w8, w0, 0xfffffffd
strb w8, [x1]

This patch adds a target hook to TargetLowering::TargetLoweringOpt and overrides it in the AArch64 backend to sign-extend an immediate operand if the upper bits are not demanded and sign-extending enables folding the immediate into the instruction.

This optimization speeds up 253.perlbmk by 5%.

http://reviews.llvm.org/D5591

Files:
  include/llvm/Target/TargetLowering.h
  lib/CodeGen/SelectionDAG/TargetLowering.cpp
  lib/Target/AArch64/AArch64ISelLowering.cpp
  lib/Target/AArch64/AArch64ISelLowering.h
  test/CodeGen/AArch64/optimize-imm.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5591.14357.patch
Type: text/x-patch
Size: 6429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141002/af901f38/attachment.bin>


More information about the llvm-commits mailing list