[DAG] optimize away an arithmetic-right-shift of a 0 or -1 value

This came up as part of:
https://reviews.llvm.org/D25485

Note that the vector case is missed because ComputeNumSignBits() is deficient for vectors.

llvm-svn: 284395
This commit is contained in:
Sanjay Patel 2016-10-17 15:58:28 +00:00
parent 95db75791e
commit 2cf6bfaf73
2 changed files with 4 additions and 3 deletions

View File

@ -4740,6 +4740,10 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
EVT VT = N0.getValueType();
unsigned OpSizeInBits = VT.getScalarSizeInBits();
// Arithmetic shifting an all-sign-bit value is a no-op.
if (DAG.ComputeNumSignBits(N0) == OpSizeInBits)
return N0;
// fold vector ops
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
if (VT.isVector()) {

View File

@ -57,14 +57,11 @@ define i32 @shl56sar57(i64 %a) #0 {
ret i32 %3
}
; FIXME
define i8 @all_sign_bit_ashr(i8 %x) {
; CHECK-LABEL: all_sign_bit_ashr:
; CHECK: # BB#0:
; CHECK-NEXT: andb $1, %dil
; CHECK-NEXT: negb %dil
; CHECK-NEXT: sarb $6, %dil
; CHECK-NEXT: movl %edi, %eax
; CHECK-NEXT: retq
;