[llvm] r268534 - [ConstantFold] Don't try to strip fp -> int bitcasts to simplify icmps

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 12:54:41 PDT 2016


Hi Tom,

I'd like this pulled into the release branch.

Thanks again,
Hal

----- Original Message -----
> From: "Hal Finkel via llvm-commits" <llvm-commits at lists.llvm.org>
> To: llvm-commits at lists.llvm.org
> Sent: Wednesday, May 4, 2016 2:37:08 PM
> Subject: [llvm] r268534 - [ConstantFold] Don't try to strip fp -> int bitcasts to simplify icmps
> 
> Author: hfinkel
> Date: Wed May  4 14:37:08 2016
> New Revision: 268534
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=268534&view=rev
> Log:
> [ConstantFold] Don't try to strip fp -> int bitcasts to simplify
> icmps
> 
> ConstantFold has logic to take icmp (bitcast x to y), null and strip
> the
> bitcast. This makes sense in general, but not if x has floating-point
> type. In
> this case, we'd need a fcmp, not an icmp, and the code will assert.
> We normally
> don't see this situation because we constant fold fp -> int bitcasts,
> however,
> we'll see it for bitcasts of ppc_fp128 -> i128. This is because that
> bitcast is
> Endian-dependent, and as a result, we don't simplify it in
> ConstantFold (we
> could, but no one has yet added the necessary logic). Regardless,
> ConstantFold
> should not depend on that canonicalization for correctness.
> 
> Added:
>     llvm/trunk/test/Transforms/IPConstantProp/fp-bc-icmp-const-fold.ll
> Modified:
>     llvm/trunk/lib/IR/ConstantFold.cpp
> 
> Modified: llvm/trunk/lib/IR/ConstantFold.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=268534&r1=268533&r2=268534&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/ConstantFold.cpp (original)
> +++ llvm/trunk/lib/IR/ConstantFold.cpp Wed May  4 14:37:08 2016
> @@ -1529,6 +1529,10 @@ static ICmpInst::Predicate evaluateICmpR
>      case Instruction::BitCast:
>      case Instruction::ZExt:
>      case Instruction::SExt:
> +      // We can't evaluate floating point casts or truncations.
> +      if (CE1Op0->getType()->isFloatingPointTy())
> +        break;
> +
>        // If the cast is not actually changing bits, and the second
>        operand is a
>        // null pointer, do the comparison with the pre-casted value.
>        if (V2->isNullValue() &&
> 
> Added:
> llvm/trunk/test/Transforms/IPConstantProp/fp-bc-icmp-const-fold.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IPConstantProp/fp-bc-icmp-const-fold.ll?rev=268534&view=auto
> ==============================================================================
> ---
> llvm/trunk/test/Transforms/IPConstantProp/fp-bc-icmp-const-fold.ll
> (added)
> +++
> llvm/trunk/test/Transforms/IPConstantProp/fp-bc-icmp-const-fold.ll
> Wed May  4 14:37:08 2016
> @@ -0,0 +1,52 @@
> +; RUN: opt -S -ipsccp < %s | FileCheck %s
> +target datalayout = "E-m:e-i64:64-n32:64"
> +target triple = "powerpc64-bgq-linux"
> +
> +define void @test(i32 signext %n) {
> +
> +; CHECK-LABEL: @test
> +
> +entry:
> +  br i1 undef, label %if.then, label %if.end
> +
> +if.then:                                          ; preds = %entry
> +  ret void
> +
> +if.end:                                           ; preds = %entry
> +  br i1 undef, label %if.then2, label %if.end4
> +
> +if.then2:                                         ; preds = %if.end
> +  unreachable
> +
> +if.end4:                                          ; preds = %if.end
> +  %sub.n = select i1 undef, i32 undef, i32 %n
> +  switch i32 %sub.n, label %if.else14 [
> +    i32 0, label %if.then9
> +    i32 1, label %if.then12
> +  ]
> +
> +if.then9:                                         ; preds = %if.end4
> +  unreachable
> +
> +if.then12:                                        ; preds = %if.end4
> +  unreachable
> +
> +if.else14:                                        ; preds = %if.end4
> +  br label %do.body
> +
> +do.body:                                          ; preds =
> %do.body, %if.else14
> +  %scale.0 = phi ppc_fp128 [ 0xM3FF00000000000000000000000000000,
> %if.else14 ], [ %scale.0, %do.body ]
> +  br i1 undef, label %do.body, label %if.then33
> +
> +if.then33:                                        ; preds = %do.body
> +  br i1 undef, label %_ZN5boost4math4signIgEEiRKT_.exit30, label
> %cond.false.i28
> +
> +cond.false.i28:                                   ; preds =
> %if.then33
> +  %0 = bitcast ppc_fp128 %scale.0 to i128
> +  %tobool.i26 = icmp slt i128 %0, 0
> +  br label %_ZN5boost4math4signIgEEiRKT_.exit30
> +
> +_ZN5boost4math4signIgEEiRKT_.exit30:              ; preds =
> %cond.false.i28, %if.then33
> +  unreachable
> +}
> +
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory


More information about the llvm-commits mailing list