This is an archive of the discontinued LLVM Phabricator instance.

[WIP][LSR] Transform div instruction to add in loop
Needs ReviewPublic

Authored by LuoYuanke on Jul 30 2023, 5:24 AM.

Details

Summary

Some target don't have div instruction or div is very expensive. For large
integer type, div is transformed to non-div instruction by expand-div-rem
pass. Transforming div to add in loop help to improve the performance.

Diff Detail

Event Timeline

LuoYuanke created this revision.Jul 30 2023, 5:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2023, 5:24 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
LuoYuanke requested review of this revision.Jul 30 2023, 5:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2023, 5:24 AM
LuoYuanke edited the summary of this revision. (Show Details)Jul 30 2023, 5:26 AM
LuoYuanke updated this revision to Diff 545496.Jul 30 2023, 6:23 PM

Add nsw and nuw flags for add instruction.

LuoYuanke updated this revision to Diff 545497.Jul 30 2023, 6:37 PM

Check if div is legal for target. If it is legal, drop the transform.

craig.topper added inline comments.
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
2254

Does div here replace the original i?

2288

Do we need to create new SCEV expression to compare? Can we ask if the StepRecurrence is a SCEVConstant and get it's value?

LuoYuanke added inline comments.Jul 31 2023, 12:07 AM
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
2254

Yes, I'll update the code of the comments to make it clear.

2288

Yes, we can just ask if StepRecurrence is one value.

Address Craig's comments.