Skip to content

Commit d9910c2

Browse files
RKSimontstellar
authored andcommitted
[DAG] Fix shift amount limit in SimplifyDemandedBits trunc(shift(x,c)) to truncated bitwidth
We lost this in D56387/rG69bc0990a9181e6eb86228276d2f59435a7fae67 - where I got the src/dst bitwidths mixed up and assumed getValidShiftAmountConstant would catch it. Patch by @craig.topper - confirmed by @carrot that it fixes PR49162 (cherry picked from commit 7ad0c57)
1 parent d44bf33 commit d9910c2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ bool TargetLowering::SimplifyDemandedBits(
20122012

20132013
const APInt *ShAmtC =
20142014
TLO.DAG.getValidShiftAmountConstant(Src, DemandedElts);
2015-
if (!ShAmtC)
2015+
if (!ShAmtC || ShAmtC->uge(BitWidth))
20162016
break;
20172017
uint64_t ShVal = ShAmtC->getZExtValue();
20182018

llvm/test/CodeGen/X86/pr49162.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ define i32* @PR49162(i32* %base, i160* %ptr160) {
1717
;
1818
; X64-LABEL: PR49162:
1919
; X64: # %bb.0:
20-
; X64-NEXT: leaq -4(%rdi), %rax
20+
; X64-NEXT: movl 8(%rsi), %eax
21+
; X64-NEXT: shll $16, %eax
22+
; X64-NEXT: cltq
23+
; X64-NEXT: sarq $16, %rax
24+
; X64-NEXT: leaq (%rdi,%rax,4), %rax
2125
; X64-NEXT: retq
2226
%load160 = load i160, i160* %ptr160, align 4
2327
%shl = shl i160 %load160, 80

0 commit comments

Comments
 (0)