Skip to content

[InstCombine] Drop Range attribute when simplifying 'fshl' based on demanded bits #124429

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

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1039,11 +1039,14 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
APInt DemandedMaskLHS(DemandedMask.lshr(ShiftAmt));
APInt DemandedMaskRHS(DemandedMask.shl(BitWidth - ShiftAmt));
if (I->getOperand(0) != I->getOperand(1)) {
if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown,
Depth + 1, Q) ||
if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, Depth + 1,
Q) ||
SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1,
Q))
Q)) {
// Range attribute may no longer hold.
I->dropPoisonGeneratingReturnAttributes();
return I;
}
} else { // fshl is a rotate
// Avoid converting rotate into funnel shift.
// Only simplify if one operand is constant.
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/Transforms/InstCombine/fsh.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1069,11 +1069,12 @@ entry:
ret <2 x i31> %res
}

;; Issue #124387 Range attribute no longer holds after operands changed.
define i8 @fshl_range_trunc(i1 %x) {
; CHECK-LABEL: @fshl_range_trunc(
; CHECK-NEXT: [[ZEXT:%.*]] = zext i1 [[X:%.*]] to i32
; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[ZEXT]], 126
; CHECK-NEXT: [[FSHL:%.*]] = call range(i32 -4, 2) i32 @llvm.fshl.i32(i32 [[OR]], i32 -2, i32 1)
; CHECK-NEXT: [[FSHL:%.*]] = call i32 @llvm.fshl.i32(i32 [[OR]], i32 -2, i32 1)
; CHECK-NEXT: [[TR:%.*]] = trunc nuw i32 [[FSHL]] to i8
; CHECK-NEXT: ret i8 [[TR]]
;
Expand Down
Loading