-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[SDAG] Fix type checks in ShrinkDemandedOp
to avoid creating invalid truncates
#92730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,10 +596,17 @@ bool TargetLowering::ShrinkDemandedOp(SDValue Op, unsigned BitWidth, | |
// Op's type. For expedience, just check power-of-2 integer types. | ||
const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||
unsigned DemandedSize = DemandedBits.getActiveBits(); | ||
// Types of LHS and RHS may differ before legalization (e.g., shl), so we | ||
// need to check both. | ||
unsigned MinWidth = | ||
std::min(Op.getOperand(0).getValueType().getScalarSizeInBits(), | ||
Op.getOperand(1).getValueType().getScalarSizeInBits()); | ||
for (unsigned SmallVTBits = llvm::bit_ceil(DemandedSize); | ||
SmallVTBits < BitWidth; SmallVTBits = NextPowerOf2(SmallVTBits)) { | ||
SmallVTBits < MinWidth; SmallVTBits = NextPowerOf2(SmallVTBits)) { | ||
EVT SmallVT = EVT::getIntegerVT(*DAG.getContext(), SmallVTBits); | ||
if (TLI.isTruncateFree(VT, SmallVT) && TLI.isZExtFree(SmallVT, VT)) { | ||
if (TLI.isTruncateFree(Op.getOperand(0).getValueType(), SmallVT) && | ||
TLI.isTruncateFree(Op.getOperand(1).getValueType(), SmallVT) && | ||
Comment on lines
+602
to
+608
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure treating this as the minimum makes sense in the shift case. The RHS type is only an accessory to the main type. It would probably make more sense to stop treating shift as a uniform binary operator, and check the preferred shift amount type for the main type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #92753. |
||
TLI.isZExtFree(SmallVT, VT)) { | ||
// We found a type with free casts. | ||
SDValue X = DAG.getNode( | ||
Op.getOpcode(), dl, SmallVT, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s | ||
|
||
; Make sure we don't crash when shrinking the shift amount before legalization. | ||
define i64 @pr92720(i64 %x) { | ||
; CHECK-LABEL: pr92720: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: movabsq $8589934592, %rax # imm = 0x200000000 | ||
; CHECK-NEXT: retq | ||
%or = or i64 %x, 255 | ||
%sub = sub i64 0, %or | ||
%shl = shl i64 1, %sub | ||
%sext = shl i64 %shl, 32 | ||
ret i64 %sext | ||
} |
Uh oh!
There was an error while loading. Please reload this page.