[PATCH] D12156: Optimize bitwise even/odd test (-x&1 -> x&1) to not use negation.

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 11:34:43 PDT 2015


majnemer accepted this revision.
majnemer added a comment.
This revision is now accepted and ready to land.

LGTM


================
Comment at: test/Transforms/InstCombine/and-with-one.ll:1-25
@@ +1,25 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i64 @test1(i64 %x) {
+; CHECK-LABEL: @test1(
+; CHECK-NOT: %sub = sub nsw i64 0, %x
+; CHECK-NOT: %and = and i64 %sub, 1
+; CHECK-NEXT: %and = and i64 %x, 1
+; CHECK-NEXT: ret i64 %and
+  %sub = sub nsw i64 0, %x
+  %and = and i64 %sub, 1
+  ret i64 %and
+}
+
+define i64 @test2(i64 %x) {
+; CHECK-LABEL: @test2(
+; CHECK-NOT: %sub = sub nsw i64 0, %x
+; CHECK-NEXT: %and = and i64 %x, 1
+; CHECK-NOT: %add = add i64 %sub, %and
+; CHECK-NEXT: %add = sub i64 %and, %x
+; CHECK-NEXT: ret i64 %add
+  %sub = sub nsw i64 0, %x
+  %and = and i64 %sub, 1
+  %add = add i64 %sub, %and
+  ret i64 %add
+}
----------------
Instead of a new file, can you add these to and2.ll ?


http://reviews.llvm.org/D12156





More information about the llvm-commits mailing list