[PATCH] D38384: [InstCombine] Don't use Builder.getTrue/False in foldICmpDivConstant

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 15:15:07 PDT 2017


craig.topper created this revision.

Builder.getTrue/False assumes a scalar comparison, but this code supports vector compares.

I'm having trouble proving that this code isn't dead due to InstSimplify so I don't have a test case. But it looked obviously wrong.


https://reviews.llvm.org/D38384

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp


Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2280,7 +2280,7 @@
     default: llvm_unreachable("Unhandled icmp opcode!");
     case ICmpInst::ICMP_EQ:
       if (LoOverflow && HiOverflow)
-        return replaceInstUsesWith(Cmp, Builder.getFalse());
+        return replaceInstUsesWith(Cmp, ConstantInt::getFalse(Cmp.getType()));
       if (HiOverflow)
         return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
                             ICmpInst::ICMP_UGE, X, LoBound);
@@ -2292,7 +2292,7 @@
                                HiBound->getUniqueInteger(), DivIsSigned, true));
     case ICmpInst::ICMP_NE:
       if (LoOverflow && HiOverflow)
-        return replaceInstUsesWith(Cmp, Builder.getTrue());
+        return replaceInstUsesWith(Cmp, ConstantInt::getTrue(Cmp.getType()));
       if (HiOverflow)
         return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
                             ICmpInst::ICMP_ULT, X, LoBound);
@@ -2306,16 +2306,16 @@
     case ICmpInst::ICMP_ULT:
     case ICmpInst::ICMP_SLT:
       if (LoOverflow == +1)   // Low bound is greater than input range.
-        return replaceInstUsesWith(Cmp, Builder.getTrue());
+        return replaceInstUsesWith(Cmp, ConstantInt::getTrue(Cmp.getType()));
       if (LoOverflow == -1)   // Low bound is less than input range.
-        return replaceInstUsesWith(Cmp, Builder.getFalse());
+        return replaceInstUsesWith(Cmp, ConstantInt::getFalse(Cmp.getType()));
       return new ICmpInst(Pred, X, LoBound);
     case ICmpInst::ICMP_UGT:
     case ICmpInst::ICMP_SGT:
       if (HiOverflow == +1)       // High bound greater than input range.
-        return replaceInstUsesWith(Cmp, Builder.getFalse());
+        return replaceInstUsesWith(Cmp, ConstantInt::getFalse(Cmp.getType()));
       if (HiOverflow == -1)       // High bound less than input range.
-        return replaceInstUsesWith(Cmp, Builder.getTrue());
+        return replaceInstUsesWith(Cmp, ConstantInt::getTrue(Cmp.getType()));
       if (Pred == ICmpInst::ICMP_UGT)
         return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
       return new ICmpInst(ICmpInst::ICMP_SGE, X, HiBound);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38384.117064.patch
Type: text/x-patch
Size: 2337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170928/a327d152/attachment.bin>


More information about the llvm-commits mailing list