[PATCH] D65815: [EarlyCSE] Add support for unary FNeg to EarlyCSE

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 10:01:31 PDT 2019


cameron.mcinally created this revision.
cameron.mcinally added reviewers: spatel, arsenm, kpn, craig.topper, milseman, JosephTremoulet.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.

Repository:
  rL LLVM

https://reviews.llvm.org/D65815

Files:
  llvm/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/test/Transforms/EarlyCSE/floatingpoint.ll


Index: llvm/test/Transforms/EarlyCSE/floatingpoint.ll
===================================================================
--- llvm/test/Transforms/EarlyCSE/floatingpoint.ll
+++ llvm/test/Transforms/EarlyCSE/floatingpoint.ll
@@ -17,9 +17,8 @@
 ; CSE unary fnegs.
 define void @fX(<4 x float> *%p, <4 x float> %a) {
        ; CHECK: %x = fneg <4 x float> %a
-       ; CHECK: %y = fneg <4 x float> %a
-       ; CHECK-NEXT:  store volatile <4 x float> %x, <4 x float>* %p
-       ; CHECK-NEXT: store volatile <4 x float> %y, <4 x float>* %p
+       ; CHECK-NEXT: store volatile <4 x float> %x, <4 x float>* %p
+       ; CHECK-NEXT: store volatile <4 x float> %x, <4 x float>* %p
        %x = fneg <4 x float> %a
        %y = fneg <4 x float> %a
        store volatile <4 x float> %x, <4 x float>* %p
Index: llvm/lib/Transforms/Scalar/EarlyCSE.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -108,11 +108,12 @@
     // This can only handle non-void readnone functions.
     if (CallInst *CI = dyn_cast<CallInst>(Inst))
       return CI->doesNotAccessMemory() && !CI->getType()->isVoidTy();
-    return isa<CastInst>(Inst) || isa<BinaryOperator>(Inst) ||
-           isa<GetElementPtrInst>(Inst) || isa<CmpInst>(Inst) ||
-           isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
-           isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst) ||
-           isa<ExtractValueInst>(Inst) || isa<InsertValueInst>(Inst);
+    return isa<CastInst>(Inst) || isa<UnaryOperator>(Inst) ||
+           isa<BinaryOperator>(Inst) || isa<GetElementPtrInst>(Inst) ||
+           isa<CmpInst>(Inst) || isa<SelectInst>(Inst) ||
+           isa<ExtractElementInst>(Inst) || isa<InsertElementInst>(Inst) ||
+           isa<ShuffleVectorInst>(Inst) || isa<ExtractValueInst>(Inst) ||
+           isa<InsertValueInst>(Inst);
   }
 };
 
@@ -163,6 +164,12 @@
 
 static unsigned getHashValueImpl(SimpleValue Val) {
   Instruction *Inst = Val.Inst;
+
+  if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(Inst)) {
+    return hash_combine(UnOp->getOpcode(), UnOp->getType(),
+                        UnOp->getOperand(0));
+  }
+
   // Hash in all of the operands as pointers.
   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(Inst)) {
     Value *LHS = BinOp->getOperand(0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65815.213642.patch
Type: text/x-patch
Size: 2385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190806/14eb98de/attachment.bin>


More information about the llvm-commits mailing list