This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Propagate constants for llvm.amdgcn.wave.reduce.umin/umax
ClosedPublic

Authored by pravinjagtap on Jul 23 2023, 10:46 PM.

Diff Detail

Event Timeline

pravinjagtap created this revision.Jul 23 2023, 10:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 10:46 PM
pravinjagtap requested review of this revision.Jul 23 2023, 10:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 10:46 PM
pravinjagtap added a reviewer: Restricted Project.Jul 23 2023, 10:54 PM

Should the change description say "propagate constants for llvm.amdgcn.wave.reduce.umin/umax"? That seems more informative.

foad added inline comments.Jul 24 2023, 5:51 AM
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
1139 ↗(On Diff #543381)

This should go in lib/Analysis/ConstantFolding.cpp instead.

llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
6197 ↗(On Diff #543381)

Tests can go in test/Transforms/InstSimplify/ConstProp/AMDGPU/.

arsenm added inline comments.Jul 24 2023, 5:52 AM
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
1139 ↗(On Diff #543381)

that's true of many folds we do here, but I thought we were supposed to avoid putting target intrinsics there. We do lose out of the benefits of being a pure analysis here though

1144 ↗(On Diff #543381)

isa<Constant> covers isa<Poison>

pravinjagtap updated this revision to Diff 543881.EditedJul 25 2023, 2:06 AM

Moved const fold impl from /lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp to
lib/Analysis/ConstantFolding.cpp

pravinjagtap added inline comments.Jul 25 2023, 2:09 AM
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.reduce.umax.ll
138

Hello @foad, I am not sure why const fold optimization is not being applied here in llc.

pravinjagtap retitled this revision from [AMDGPU] Perform basic folds on llvm.amdgcn.wave.reduce.umin/umax. to [AMDGPU] Propagate constants for llvm.amdgcn.wave.reduce.umin/umax.Jul 25 2023, 2:10 AM
foad added inline comments.Jul 25 2023, 2:17 AM
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.reduce.umax.ll
138

llc does not run IR optimization passes. Use opt for that.

pravinjagtap added inline comments.Jul 25 2023, 2:41 AM
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.reduce.umax.ll
138

If you notice, poison_value test point is being modified after early-cse pass during llc invocation in this test because of the current change in ConstantFolding.cpp. I was expecting same for const_value test point here.

foad added inline comments.Jul 25 2023, 2:59 AM
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.reduce.umax.ll
138

Why do you think "const fold optimization is not being applied here"? Looking at the ISA, it just stores a constant value. What did you expect to see?

pravinjagtap added inline comments.Jul 25 2023, 3:05 AM
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.reduce.umax.ll
138

Agree. Sorry, I overlooked. The optimization is applied in this case also.

arsenm added inline comments.Jul 25 2023, 6:59 AM
llvm/lib/Analysis/ConstantFolding.cpp
2851

It doesn't need to be a literal int isa<Constant> should cover every case

llvm/test/Transforms/InstSimplify/ConstProp/AMDGPU/wave.reduce.ll
34

Also try something exotic, like ptrtoint of a global declaration

Addressed review comments

pravinjagtap added inline comments.Jul 25 2023, 6:47 PM
llvm/test/Transforms/InstSimplify/ConstProp/AMDGPU/wave.reduce.ll
65

This usecase is not being optimized (const-fold).

arsenm accepted this revision.Jul 26 2023, 10:20 AM

LGTM with the spurious include dropped

llvm/lib/Analysis/ConstantFolding.cpp
63

Don't add new include

llvm/test/Transforms/InstSimplify/ConstProp/AMDGPU/wave.reduce.ll
65

Don't see why that would be but it's unimportant

This revision is now accepted and ready to land.Jul 26 2023, 10:20 AM

Addressed review comments

This revision was landed with ongoing or failed builds.Jul 26 2023, 8:49 PM
This revision was automatically updated to reflect the committed changes.