[ARM64] Prevent bit extraction to be adjusted by following shift
authorWeiming Zhao <weimingz@codeaurora.org>
Wed, 30 Apr 2014 21:07:24 +0000 (21:07 +0000)
committerWeiming Zhao <weimingz@codeaurora.org>
Wed, 30 Apr 2014 21:07:24 +0000 (21:07 +0000)
commitfa1cf8cd6816491cf8b78ae24cce68d640be459f
treef69d0f61155a2fa90f5fe86e5a0e242920181b44
parent79844fc3d269d2fccee1de3e0b8b6c374ce63ff2
[ARM64] Prevent bit extraction to be adjusted by following shift

For pattern like ((x >> C1) & Mask) << C2, DAG combiner may convert it
into (x >> (C1-C2)) & (Mask << C2), which makes pattern matching of ubfx
more difficult.
For example:
Given
  %shr = lshr i64 %x, 4
  %and = and i64 %shr, 15
  %arrayidx = getelementptr inbounds [8 x [64 x i64]]* @arr, i64 0, %i64 2, i64 %and
  %0 = load i64* %arrayidx
With current shift folding, it takes 3 instrs to compute base address:
  lsr x8, x0, #1
  and x8, x8, #0x78
  add x8, x9, x8

If using ubfx, it only needs 2 instrs:
  ubfx  x8, x0, #4, #4
  add x8, x9, x8, lsl #3

This fixes bug 19589

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207702 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Target/TargetLowering.h
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/Target/ARM64/ARM64ISelLowering.cpp
lib/Target/ARM64/ARM64ISelLowering.h
test/CodeGen/ARM64/bitfield-extract.ll