This is an archive of the discontinued LLVM Phabricator instance.

Remove redundant folding of bswap(bswap(x))
AbandonedPublic

Authored by arsenm on Aug 13 2014, 9:58 AM.

Details

Reviewers
None
Summary

Idempotent intrinsics are already generally handled, so no need to special case bswap.

Diff Detail

Event Timeline

arsenm updated this revision to Diff 12460.Aug 13 2014, 9:58 AM
arsenm retitled this revision from to Remove redundant folding of bswap(bswap(x)).
arsenm updated this object.
arsenm edited the test plan for this revision. (Show Details)
arsenm added a subscriber: Unknown Object (MLST).
// bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
if (match(IIOperand, m_Trunc(m_BSwap(m_Value(X))))) {
  unsigned C = X->getType()->getPrimitiveSizeInBits() -

Index: test/Transforms/InstSimplify/call.ll

  • test/Transforms/InstSimplify/call.ll

+++ test/Transforms/InstSimplify/call.ll
@@ -102,6 +102,17 @@

ret float %r4

}

+declare i32 @llvm.bswap.i32(i32) nounwind readnone
+
+; CHECK-LABEL: @test_idempotence_2(
+; CHECK: bswap

What does this match? Didn't we remove the bswap?

In general, it is probably better to match the code that is generated
in a bit more detail. In particular, this function is so small that
you should be able to just use a few CHECK-NEXT until the ret.

+; CHECK-NOT: bswap
+define i32 @test_idempotence_2(i32 %a) {
+ %a0 = call i32 @llvm.bswap.i32(i32 %a)
+ %a1 = call i32 @llvm.bswap.i32(i32 %a0)
+ ret i32 %a1
+}
+

arsenm abandoned this revision.Aug 13 2014, 10:58 AM

This is just a thinko. I was misreading this as bswap(bswap(x)) -> bswap(x), but it actually removes the bswap which makes more sense