[PATCH] D22601: [SCCP] Mark constant xor %blah, %blah even if the lattice value is overdefined

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 15:00:26 PDT 2016


davide created this revision.
davide added a reviewer: eli.friedman.
davide added a subscriber: llvm-commits.

I think this is OK, but there might be cases where this break I'm currently missing.
In general, it should be able to avoid some spurious overdefined values, which is good.

https://reviews.llvm.org/D22601

Files:
  lib/Transforms/Scalar/SCCP.cpp
  test/Transforms/SCCP/xor.ll

Index: test/Transforms/SCCP/xor.ll
===================================================================
--- /dev/null
+++ test/Transforms/SCCP/xor.ll
@@ -0,0 +1,10 @@
+; RUN: opt -S -sccp %s | FileCheck %s
+
+define i32 @myxor(i32 %x) {
+  %patatino = xor i32 %x, %x
+  ret i32 %patatino
+}
+
+; CHECK: define i32 @myxor(i32 %x) {
+; CHECK-NEXT:   ret i32 0
+; CHECK-NEXT: }
Index: lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- lib/Transforms/Scalar/SCCP.cpp
+++ lib/Transforms/Scalar/SCCP.cpp
@@ -918,6 +918,15 @@
   // Otherwise, one of our operands is overdefined.  Try to produce something
   // better than overdefined with some tricks.
 
+  // If this is a xor %blah, %blah, it doesn't matter if %blah is overdefined,
+  // we can just mark that constant.
+  if (I.getOpcode() == Instruction::Xor) {
+	  if (I.getOperand(0) == I.getOperand(1)) {
+		  markConstant(IV, &I, Constant::getNullValue(I.getType()));
+		  return;
+	  }
+  }
+
   // If this is an AND or OR with 0 or -1, it doesn't matter that the other
   // operand is overdefined.
   if (I.getOpcode() == Instruction::And || I.getOpcode() == Instruction::Or) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22601.64774.patch
Type: text/x-patch
Size: 1185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160720/e53a4206/attachment.bin>


More information about the llvm-commits mailing list