OSDN Git Service

[InstCombine] Use ConstantExpr::getBinOpIdentity to implement getIdentityValue.
authorCraig Topper <craig.topper@gmail.com>
Tue, 11 Apr 2017 17:42:40 +0000 (17:42 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 11 Apr 2017 17:42:40 +0000 (17:42 +0000)
This removes a TODO in getIdentityValue and may allow some transforms to occur earlier. But I was unable to find any transforms we didn't already handle.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299966 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstructionCombining.cpp

index 4782f47..99243b7 100644 (file)
@@ -455,16 +455,11 @@ static bool RightDistributesOverLeft(Instruction::BinaryOps LOp,
 
 /// This function returns identity value for given opcode, which can be used to
 /// factor patterns like (X * 2) + X ==> (X * 2) + (X * 1) ==> X * (2 + 1).
-static Value *getIdentityValue(Instruction::BinaryOps OpCode, Value *V) {
+static Value *getIdentityValue(Instruction::BinaryOps Opcode, Value *V) {
   if (isa<Constant>(V))
     return nullptr;
 
-  if (OpCode == Instruction::Mul)
-    return ConstantInt::get(V->getType(), 1);
-
-  // TODO: We can handle other cases e.g. Instruction::And, Instruction::Or etc.
-
-  return nullptr;
+  return ConstantExpr::getBinOpIdentity(Opcode, V->getType());
 }
 
 /// This function factors binary ops which can be combined using distributive