This is an archive of the discontinued LLVM Phabricator instance.

[instcombine] Test for zero initialisation optimisation of a product given fast flags
ClosedPublic

Authored by zjaffal on Aug 12 2022, 3:10 AM.

Details

Summary

Given a zero initialised variable iterating through an array and multiplying its elements, the optimiser should be able to remove the loop safely and return the initial value because fast math flags are enabled.

double arr_d[1000];
double f_prod = 0;
for (size_t i = 0; i < 1000; i++){
  f_prod *= arr_d[i];
}

The loop here can be deleted and we can return f_prod instead

Diff Detail

Event Timeline

zjaffal created this revision.Aug 12 2022, 3:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 3:10 AM
zjaffal published this revision for review.Aug 12 2022, 5:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 5:54 AM
fhahn added a comment.Aug 12 2022, 8:12 AM

I think the title/description needs updating to make clear this just adds tests.

[instcombine] Check for zero initialisation optimisation of a product given fast flags are enabled in clang.

Also it's not really Clang related, as this is a generic IR optimization, so it is best to drop the reference to Clang from the title.

llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll
22

Could you pass this as an argument to the tests to avoid reading memory that's not initialized?

167

I think it would be better to pass this value as argument.

242

I think it would be better to pass this condition as argument rather than having a trivial comparison.

zjaffal updated this revision to Diff 452599.Aug 15 2022, 1:03 AM

pass constants and arrays as function parameters

zjaffal updated this revision to Diff 452705.Aug 15 2022, 9:29 AM
zjaffal marked 3 inline comments as done.

Updating D131757: [instcombine] Check for zero initialisation optimisation of a product given fast flags are enabled in clang.

fhahn added a comment.Aug 15 2022, 9:32 AM

It looks like you accidentally uploaded the wrong patch here. Originally this just added the tests. (Also the title needs updating to avoid confusion)

zjaffal updated this revision to Diff 452712.Aug 15 2022, 9:35 AM

Updating D131757: [instcombine] Check for zero initialisation optimisation of a product given fast flags are enabled in clang.

zjaffal updated this revision to Diff 452717.Aug 15 2022, 9:41 AM

Updating D131757: [instcombine] Check for zero initialisation optimisation of a product given fast flags are enabled in clang.

zjaffal retitled this revision from [instcombine] Check for zero initialisation optimisation of a product given fast flags are enabled in clang. to [instcombine] Test for zero initialisation optimisation of a product given fast flags.Aug 15 2022, 10:09 AM
fhahn added inline comments.Aug 16 2022, 1:02 AM
llvm/test/Transforms/InstCombine/remove-loop-phi-fastmul.ll
234

might be good to also have a variant of this test that doesn't have 0.0 as incoming value.

zjaffal updated this revision to Diff 452933.Aug 16 2022, 2:51 AM

Updating D131757: [instcombine] Test for zero initialisation optimisation of a product given fast flags

fhahn accepted this revision.Aug 16 2022, 5:54 AM

LGTM, thanks!

This revision is now accepted and ready to land.Aug 16 2022, 5:54 AM