This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Do not fold `cmp(d|w)` and `subf` instruction to `subf.` if `nsw` is not present
ClosedPublic

Authored by lkail on Oct 26 2020, 7:15 AM.

Details

Summary

In PPCInstrInfo::optimizeCompareInstr we seek opportunities to fold cmp(d|w) and subf as an subf.. However, if subf. gets overflow, cr0 can't reflect the correct order, violating the semantics of cmp(d|w).

Fixed https://bugs.llvm.org/show_bug.cgi?id=47830.

Diff Detail

Event Timeline

lkail created this revision.Oct 26 2020, 7:15 AM
lkail requested review of this revision.Oct 26 2020, 7:15 AM
lkail updated this revision to Diff 307509.Nov 24 2020, 8:52 PM

Rebased.

lkail edited the summary of this revision. (Show Details)Dec 1 2020, 1:47 AM
nemanjai accepted this revision.Dec 29 2020, 5:06 AM

LGTM with a minor nit.

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
2144

Please add a note why this is OK when equalityOnly is set.

This revision is now accepted and ready to land.Dec 29 2020, 5:06 AM
lkail updated this revision to Diff 314050.EditedDec 29 2020, 6:56 PM

Update comment and I've pre-commit a mir test https://github.com/llvm/llvm-project/commit/e3e25cfb44bc2a35e3b53d62d37c27b7d13157b6 to demonstrate the situation when equalityOnly is true. The codegen of the test case doesn't change with this patch.

lkail updated this revision to Diff 314053.Dec 29 2020, 7:03 PM