This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Simplify select i1 ConstExpr, i1 true, i1 false to ConstExpr
ClosedPublic

Authored by StephenFan on May 28 2023, 8:11 AM.

Details

Summary

select i1 non-const, i1 true, i1 false has been optimized to
non-const. There is no reason that we can not optimize `select i1
ConstExpr, i1 true, i1 false` to ConstExpr.

Diff Detail

Event Timeline

StephenFan created this revision.May 28 2023, 8:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2023, 8:11 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
StephenFan requested review of this revision.May 28 2023, 8:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2023, 8:11 AM
nikic added inline comments.May 28 2023, 9:01 AM
llvm/test/Transforms/InstSimplify/select.ll
892

Outdated comment. We should also have a test where the constant expression is poison-generating.

Add poison generating constexpr test

nikic accepted this revision.May 29 2023, 12:08 AM

LGTM

llvm/test/Transforms/InstSimplify/select.ll
892

Outdated comments are still there.

This revision is now accepted and ready to land.May 29 2023, 12:08 AM
khei4 added a subscriber: khei4.May 29 2023, 7:10 PM
khei4 added inline comments.
llvm/test/Transforms/InstSimplify/select-inseltpoison.ll
890

I think
i32 ptrtoint (ptr getelementptr inbounds ([3 x ptr], ptr @a, i64 0, i64 1) to i32) doesn't produce poison.
index seems valid so maybe
i32 ptrtoint (ptr getelementptr inbounds ([3 x ptr], ptr @a, i64 1, i64 0) to i32) ?

nikic added inline comments.May 30 2023, 4:12 AM
llvm/test/Transforms/InstSimplify/select-inseltpoison.ll
890

Yes, strictly speaking this is also safe to fold, but would require analysis we don't currently do.

To make it actually poison you'd need something like i32 ptrtoint (ptr getelementptr inbounds ([3 x ptr], ptr @a, i64 2) to i32).

Update test.