2010-01-12 01:03:47 +08:00
|
|
|
; RUN: llc < %s | FileCheck %s
|
|
|
|
|
2009-05-24 01:29:48 +08:00
|
|
|
; Check that the shr(shl X, 56), 48) is not mistakenly turned into
|
|
|
|
; a shr (X, -8) that gets subsequently "optimized away" as undef
|
|
|
|
; PR4254
|
2010-01-12 01:03:47 +08:00
|
|
|
|
[X86] Improve shift combining
This folds (ashr (shl a, [56,48,32,24,16]), SarConst)
into (shl, (sext (a), [56,48,32,24,16] - SarConst))
or into (lshr, (sext (a), SarConst - [56,48,32,24,16]))
depending on sign of (SarConst - [56,48,32,24,16])
sexts in X86 are MOVs.
The MOVs have the same code size as above SHIFTs (only SHIFT by 1 has lower code size).
However the MOVs have 2 advantages to SHIFTs on x86:
1. MOVs can write to a register that differs from source.
2. MOVs accept memory operands.
This fixes PR24373.
Patch by: evgeny.v.stupachenko@intel.com
Differential Revision: http://reviews.llvm.org/D13161
llvm-svn: 255761
2015-12-16 19:22:37 +08:00
|
|
|
; after fixing PR24373
|
|
|
|
; shlq $56, %rdi
|
|
|
|
; sarq $48, %rdi
|
|
|
|
; folds into
|
|
|
|
; movsbq %dil, %rax
|
|
|
|
; shlq $8, %rax
|
|
|
|
; which is better for x86
|
|
|
|
|
2009-05-24 01:29:48 +08:00
|
|
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
|
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
|
|
|
|
define i64 @foo(i64 %b) nounwind readnone {
|
|
|
|
entry:
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: foo:
|
[X86] Improve shift combining
This folds (ashr (shl a, [56,48,32,24,16]), SarConst)
into (shl, (sext (a), [56,48,32,24,16] - SarConst))
or into (lshr, (sext (a), SarConst - [56,48,32,24,16]))
depending on sign of (SarConst - [56,48,32,24,16])
sexts in X86 are MOVs.
The MOVs have the same code size as above SHIFTs (only SHIFT by 1 has lower code size).
However the MOVs have 2 advantages to SHIFTs on x86:
1. MOVs can write to a register that differs from source.
2. MOVs accept memory operands.
This fixes PR24373.
Patch by: evgeny.v.stupachenko@intel.com
Differential Revision: http://reviews.llvm.org/D13161
llvm-svn: 255761
2015-12-16 19:22:37 +08:00
|
|
|
; CHECK: movsbq %dil, %rax
|
|
|
|
; CHECK: shlq $8, %rax
|
|
|
|
; CHECK: orq $1, %rax
|
2009-05-24 01:29:48 +08:00
|
|
|
%shl = shl i64 %b, 56 ; <i64> [#uses=1]
|
|
|
|
%shr = ashr i64 %shl, 48 ; <i64> [#uses=1]
|
|
|
|
%add5 = or i64 %shr, 1 ; <i64> [#uses=1]
|
|
|
|
ret i64 %add5
|
|
|
|
}
|