Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4845052
[AMDGPU] expand-fp: Change frem expansion criterion
frederik-h Sep 12, 2025
534b3e2
Revert Operation Action for frem to Expand
frederik-h Sep 12, 2025
7dee6b1
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Sep 12, 2025
61ca19c
[AMDGPU] expand-fp: Add early exit for targets that don't require any…
frederik-h Sep 16, 2025
0a30d40
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Sep 16, 2025
c1814f0
Review changes
frederik-h Sep 16, 2025
a752a2f
fixup! Review changes
frederik-h Sep 16, 2025
307252a
Try fix Windows build problem
frederik-h Sep 16, 2025
4728696
Furhter fixup for Windows build
frederik-h Sep 16, 2025
77d862b
Change ISD::FREM legalization actions from Expand to LibCall for scal…
frederik-h Oct 2, 2025
df7066c
expand-fp: always expand frem if legalization action is "Expand"
frederik-h Oct 16, 2025
53fdc7a
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Oct 16, 2025
a33ab1d
Revert deletion of comment line
frederik-h Oct 16, 2025
a58e1c7
Add back deleted line
frederik-h Oct 16, 2025
1ea0b3a
clang-format changes
frederik-h Oct 16, 2025
4d5d984
Replace two function uses by better llvm alternatives
frederik-h Oct 17, 2025
17f470b
trigger CI
frederik-h Oct 17, 2025
4225845
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Oct 17, 2025
961689b
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Oct 20, 2025
1a59160
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Oct 20, 2025
1f6811d
fixup! Merge remote-tracking branch 'upstream/main' into expand-fp-fr…
frederik-h Oct 20, 2025
91cf7ce
trigger build
frederik-h Oct 20, 2025
48665e5
Merge remote-tracking branch 'upstream/main' into expand-fp-frem-expa…
frederik-h Oct 20, 2025
f2b7181
Trigger CI
frederik-h Oct 21, 2025
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
37 changes: 25 additions & 12 deletions llvm/lib/CodeGen/ExpandFp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,22 @@ static RTLIB::Libcall fremToLibcall(Type *Ty) {
llvm_unreachable("Unknown floating point type");
}

/* Return true if, according to \p LibInfo, the target either directly
supports the frem instruction for the \p Ty, has a custom lowering,
or uses a libcall. */
static bool targetSupportsFrem(const TargetLowering &TLI, Type *Ty) {
if (!TLI.isOperationExpand(ISD::FREM, EVT::getEVT(Ty)))
return true;

return TLI.getLibcallName(fremToLibcall(Ty->getScalarType()));
/// Return true if the pass should expand a "frem" instruction of the
/// given \p Ty for the target represented by \p TLI. Expansion
/// should happen if the legalization for the scalar type uses a
/// non-existing libcall. The scalar type is considered because it is
/// easier to do so and it is highly unlikely that a vector type can
/// be legalized without a libcall if the scalar type cannot.
static bool shouldExpandFremType(const TargetLowering &TLI, Type *Ty) {
Type *ScalarTy = Ty->getScalarType();
EVT VT = EVT::getEVT(ScalarTy);

TargetLowering::LegalizeAction LA = TLI.getOperationAction(ISD::FREM, VT);
if (LA != TargetLowering::LegalizeAction::LibCall)
return false;

bool MissingLibcall = !TLI.getLibcallName(fremToLibcall(ScalarTy));
return MissingLibcall && FRemExpander::canExpandType(ScalarTy);
}

static bool runImpl(Function &F, const TargetLowering &TLI,
Expand All @@ -1000,8 +1008,8 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
if (ExpandFpConvertBits != llvm::IntegerType::MAX_INT_BITS)
MaxLegalFpConvertBitWidth = ExpandFpConvertBits;

if (MaxLegalFpConvertBitWidth >= llvm::IntegerType::MAX_INT_BITS)
return false;
bool TargetSkipExpandLargeFp =
MaxLegalFpConvertBitWidth >= llvm::IntegerType::MAX_INT_BITS;

for (auto &I : instructions(F)) {
switch (I.getOpcode()) {
Expand All @@ -1011,8 +1019,7 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
if (Ty->isScalableTy())
continue;

if (targetSupportsFrem(TLI, Ty) ||
!FRemExpander::canExpandType(Ty->getScalarType()))
if (!shouldExpandFremType(TLI, Ty))
continue;

Replace.push_back(&I);
Expand All @@ -1022,6 +1029,9 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
}
case Instruction::FPToUI:
case Instruction::FPToSI: {
if (TargetSkipExpandLargeFp)
continue;

// TODO: This pass doesn't handle scalable vectors.
if (I.getOperand(0)->getType()->isScalableTy())
continue;
Expand All @@ -1039,6 +1049,9 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
}
case Instruction::UIToFP:
case Instruction::SIToFP: {
if (TargetSkipExpandLargeFp)
continue;

// TODO: This pass doesn't handle scalable vectors.
if (I.getOperand(0)->getType()->isScalableTy())
continue;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ AMDGPUTargetLowering::AMDGPUTargetLowering(const TargetMachine &TM,
setOperationAction({ISD::LRINT, ISD::LLRINT}, {MVT::f16, MVT::f32, MVT::f64},
Expand);

setOperationAction(ISD::FREM, {MVT::f16, MVT::f32, MVT::f64}, Expand);
setOperationAction(ISD::FREM, {MVT::f16, MVT::f32, MVT::f64}, LibCall);

if (Subtarget->has16BitInsts()) {
setOperationAction(ISD::IS_FPCLASS, {MVT::f16, MVT::f32, MVT::f64}, Legal);
Expand Down
Loading