[llvm-commits] [PATCH] Teach IRBuilder about simplifying BinOp(Value, Constant)

Eli Friedman eli.friedman at gmail.com
Mon Jan 5 13:01:29 PST 2009


On Mon, Jan 5, 2009 at 1:25 AM, Török Edwin <edwintorok at gmail.com> wrote:
> I added back the Constant* functions in ConstantFolder/TargetFolder,
> since llvm-gcc is using them (called with constant* params, expecting
> constant* return).

+      case Instruction::UDiv:
+      case Instruction::SDiv:
+        // udiv/sdiv 0, X -> 0
+        // This also transforms udiv 0, 0 (undefined behaviour) -> 0.
+        if (CLHS && CLHS->isZero())
+          return CLHS;
+        // udiv/sdiv X, 1 -> X
+        if (CRHS && CRHS->isOne())
+          return LHS;
+        // Don't simplify udiv X, 0 at this point, because it could be used
+        // to knowingly generate a SIGFPE.
+        break;

Go ahead and simplify udiv X, 0... we don't make any guarantees about
what happens when you perform an illegal division, and half-baked
attempts to preserve that behavior aren't helpful.  If someone really
wants a SIGFPE, they should use inline asm or something like that.
Actually, you could just remove the comment, though, since it's not
likely to show up in normal code.

-Eli




More information about the llvm-commits mailing list