Skip to content

Commit f4d058f

Browse files
authored
[SelectionDAG] Ignore LegalTypes parameter in TargetLoweringBase::getShiftAmountTy. (#97645)
When this flag was false, `getShiftAmountTy` would return `PointerTy` instead of the target's preferred shift amount type for scalar shifts. This used to be needed when the target's preferred type wasn't large enough to support the shift amount needed for an illegal type. For example, any scalar type larger than i256 on X86 since X86's preferred shift amount type is i8. For a while now, we've had code that uses `MVT::i32` if `LegalTypes` is true, but the target's preferred type is too small. This fixed a repeated cause of crashes where the `LegalTypes` flag wasn't set to false when illegal types could be present. This has made it unnecessary to set the `LegalTypes` flag correctly, and as a result more and more places don't. So I think its time for this flag to go away. This first patch just disconnects the flag. The interface and all callers will be cleaned up in follow up patches. The X86 test change is because we now have the same shift type for both shifts in a (srl (sub C, (shl X, 32), 32) sequence. This makes the shift amounts appear equal in value and type which is needed to enable a combine.
1 parent 79d6f52 commit f4d058f

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,7 @@ EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy, const DataLayout &DL,
10571057
assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
10581058
if (LHSTy.isVector())
10591059
return LHSTy;
1060-
MVT ShiftVT =
1061-
LegalTypes ? getScalarShiftAmountTy(DL, LHSTy) : getPointerTy(DL);
1060+
MVT ShiftVT = getScalarShiftAmountTy(DL, LHSTy);
10621061
// If any possible shift value won't fit in the prefered type, just use
10631062
// something safe. Assume it will be legalized when the shift is expanded.
10641063
if (ShiftVT.getSizeInBits() < Log2_32_Ceil(LHSTy.getSizeInBits()))

llvm/test/CodeGen/X86/shift-combine.ll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,10 @@ define i64 @ashr_add_neg_shl_i32(i64 %r) nounwind {
444444
define i64 @ashr_add_neg_shl_i8(i64 %r) nounwind {
445445
; X86-LABEL: ashr_add_neg_shl_i8:
446446
; X86: # %bb.0:
447-
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
448-
; X86-NEXT: shll $24, %eax
449-
; X86-NEXT: movl $33554432, %edx # imm = 0x2000000
450-
; X86-NEXT: subl %eax, %edx
451-
; X86-NEXT: movl %edx, %eax
452-
; X86-NEXT: sarl $24, %eax
447+
; X86-NEXT: movb $2, %al
448+
; X86-NEXT: subb {{[0-9]+}}(%esp), %al
449+
; X86-NEXT: movsbl %al, %eax
450+
; X86-NEXT: movl %eax, %edx
453451
; X86-NEXT: sarl $31, %edx
454452
; X86-NEXT: retl
455453
;

0 commit comments

Comments
 (0)