If we know that it's a constant being casted, propagate through the cast
authorNick Lewycky <nicholas@mxc.ca>
Fri, 12 Jan 2007 01:23:53 +0000 (01:23 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 12 Jan 2007 01:23:53 +0000 (01:23 +0000)
instruction. Doesn't work the other way though (can't recover bits that
have been truncated).

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

lib/Transforms/Scalar/PredicateSimplifier.cpp

index 8defb871b763db1773ec029a23d94a2dbb7b1739..33dee090986d18f02927f74a49d287ef26bf57db 100644 (file)
@@ -1285,8 +1285,17 @@ namespace {
                    IG.canonicalize(SI->getFalseValue(), Top)) {
           add(SI, SI->getTrueValue(), ICmpInst::ICMP_EQ, NewContext);
         }
+      } else if (CastInst *CI = dyn_cast<CastInst>(I)) {
+        if (CI->getDestTy()->isFPOrFPVector()) return;
+
+        if (Constant *C = dyn_cast<Constant>(
+                IG.canonicalize(CI->getOperand(0), Top))) {
+          add(CI, ConstantExpr::getCast(CI->getOpcode(), C, CI->getDestTy()),
+              ICmpInst::ICMP_EQ, NewContext);
+        }
+
+        // TODO: "%a = cast ... %b" where %b is NE/LT/GT a constant.
       }
-      // TODO: CastInst "%a = cast ... %b" where %b is EQ or NE a constant.
     }
 
     /// solve - process the work queue