This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold branches with irrelevant conditions to a constant
ClosedPublic

Authored by davide on Aug 21 2017, 12:01 PM.

Details

Summary

InstCombine folds instructions with irrelevant conditions to undef.
This, as Nuno confirmed is a bug.
https://bugs.llvm.org/show_bug.cgi?id=33409#c1

Given the original motivation for the change is that of removing an USE, I suggested to just fold to a constant instead (which seems to reach the same goal without side effects).

Fixes PR33409 (which also contains a more detailed discussion of the bug).

Diff Detail

Repository
rL LLVM

Event Timeline

davide created this revision.Aug 21 2017, 12:01 PM
majnemer added inline comments.Aug 21 2017, 2:36 PM
lib/Transforms/InstCombine/InstructionCombining.cpp
2263 ↗(On Diff #112026)

I think we want !isa<ConstantInt> instead of Constant. The branch condition could be some crazy (icmp i32 (ptrtoint ... to i32), ...) and replacing it with false is more canonical.

Indeed. I changed it & added a test while I was there.

davide updated this revision to Diff 112143.Aug 22 2017, 3:23 AM

Address David's comments.

reames accepted this revision.Aug 22 2017, 1:43 PM

LGTM

This revision is now accepted and ready to land.Aug 22 2017, 1:43 PM
This revision was automatically updated to reflect the committed changes.