[llvm] r310542 - [InstSimplify] Add test cases that show that simplifySelectWithICmpCond doesn't work with non-canonical comparisons.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 18:02:02 PDT 2017


Author: ctopper
Date: Wed Aug  9 18:02:02 2017
New Revision: 310542

URL: http://llvm.org/viewvc/llvm-project?rev=310542&view=rev
Log:
[InstSimplify] Add test cases that show that simplifySelectWithICmpCond doesn't work with non-canonical comparisons.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/select.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=310542&r1=310541&r2=310542&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Aug  9 18:02:02 2017
@@ -3660,6 +3660,7 @@ static Value *simplifySelectWithICmpCond
 
   // FIXME: This code is nearly duplicated in InstCombine. Using/refactoring
   // decomposeBitTestICmp() might help.
+  // FIXME this should support ICMP_SLE/SGE forms as well
   if (ICmpInst::isEquality(Pred) && match(CmpRHS, m_Zero())) {
     Value *X;
     const APInt *Y;

Modified: llvm/trunk/test/Transforms/InstSimplify/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/select.ll?rev=310542&r1=310541&r2=310542&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/select.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/select.ll Wed Aug  9 18:02:02 2017
@@ -46,6 +46,21 @@ define i32 @test4(i32 %X) {
   ret i32 %cond
 }
 
+; Same as above, but the compare isn't canonical
+; TODO: we should be able to simplify this
+define i32 @test4noncanon(i32 %X) {
+; CHECK-LABEL: @test4noncanon(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i32 [[X:%.*]], -1
+; CHECK-NEXT:    [[OR:%.*]] = or i32 [[X]], -2147483648
+; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[OR]]
+; CHECK-NEXT:    ret i32 [[COND]]
+;
+  %cmp = icmp sle i32 %X, -1
+  %or = or i32 %X, -2147483648
+  %cond = select i1 %cmp, i32 %X, i32 %or
+  ret i32 %cond
+}
+
 define i32 @test5(i32 %X) {
 ; CHECK-LABEL: @test5(
 ; CHECK-NEXT:    ret i32 %X
@@ -96,6 +111,21 @@ define i32 @test9(i32 %X) {
   %or = or i32 %X, -2147483648
   %cond = select i1 %cmp, i32 %or, i32 %X
   ret i32 %cond
+}
+
+; Same as above, but the compare isn't canonical
+; TODO: we should be able to simplify this
+define i32 @test9noncanon(i32 %X) {
+; CHECK-LABEL: @test9noncanon(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[OR:%.*]] = or i32 [[X]], -2147483648
+; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], i32 [[OR]], i32 [[X]]
+; CHECK-NEXT:    ret i32 [[COND]]
+;
+  %cmp = icmp sge i32 %X, 0
+  %or = or i32 %X, -2147483648
+  %cond = select i1 %cmp, i32 %or, i32 %X
+  ret i32 %cond
 }
 
 define i32 @test10(i32 %X) {




More information about the llvm-commits mailing list