Implement "strength reduction" of X <= C and X >= C
authorChris Lattner <sabre@nondot.org>
Mon, 23 Feb 2004 05:47:48 +0000 (05:47 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 23 Feb 2004 05:47:48 +0000 (05:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11735 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index d12674d3bf77dacd3206f3f0b0f2ffb673e2fec7..f23c10fcbd8e8df3d807e2d106a2a7b35c5d1998 100644 (file)
@@ -1369,6 +1369,15 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
       if (I.getOpcode() == Instruction::SetLE)       // A <= MAX-1 -> A != MAX
         return BinaryOperator::create(Instruction::SetNE, Op0, AddOne(CI));
     }
+
+    // If we still have a setle or setge instruction, turn it into the
+    // appropriate setlt or setgt instruction.  Since the border cases have
+    // already been handled above, this requires little checking.
+    //
+    if (I.getOpcode() == Instruction::SetLE)
+      return BinaryOperator::create(Instruction::SetLT, Op0, AddOne(CI));
+    if (I.getOpcode() == Instruction::SetGE)
+      return BinaryOperator::create(Instruction::SetGT, Op0, SubOne(CI));
   }
 
   // Test to see if the operands of the setcc are casted versions of other