This is an archive of the discontinued LLVM Phabricator instance.

[ConstExpr] Remove div/rem constant expressions
ClosedPublic

Authored by nikic on Jul 5 2022, 9:38 AM.

Details

Summary

D128820 stopped creating div/rem constant expressions by default; this patch removes support for them entirely.

The getUDiv(), getExactUDiv(), getSDiv(), getExactSDiv(), getURem() and getSRem() on ConstantExpr are removed, and ConstantExpr::get() now only accepts binary operators for which ConstantExpr::isSupportedBinOp() returns true. Uses of these methods may be replaced either by corresponding IRBuilder methods, or ConstantFoldBinaryOpOperands (if a constant result is required).

On the C API side, LLVMConstUDiv, LLVMConstExactUDiv, LLVMConstSDiv, LLVMConstExactSDiv, LLVMConstURem and LLVMConstSRem are removed and corresponding LLVMBuild methods should be used.

Importantly, this also means that constant expressions can no longer trap! This patch still keeps the canTrap() method to minimize diff -- I plan to drop it in a separate NFC patch (but could fold that into here as well).

Diff Detail

Event Timeline

nikic created this revision.Jul 5 2022, 9:38 AM
Herald added a project: Restricted Project. · View Herald Transcript
nikic requested review of this revision.Jul 5 2022, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2022, 9:38 AM
reames accepted this revision.Jul 5 2022, 12:33 PM

LGTM.

Not required, but I'd encourage you to avoid deleting the tests. I spot checked and didn't see any where removing wasn't at least defensible, but I'd generally prefer to see the constant exprs replaces with instructions and the tests kept as much as possible. I worry that tests which appear to exercise only trapping constants might be the only trapping coverage we have at all for a given transform.

This revision is now accepted and ready to land.Jul 5 2022, 12:33 PM
This revision was landed with ongoing or failed builds.Jul 6 2022, 1:13 AM
This revision was automatically updated to reflect the committed changes.
llvm/test/Transforms/SimplifyCFG/PR16069.ll