Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit 5813ee1

Browse files
author
Hal Finkel
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268534 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 128ff37 commit 5813ee1

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/IR/ConstantFold.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,10 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
15291529
case Instruction::BitCast:
15301530
case Instruction::ZExt:
15311531
case Instruction::SExt:
1532+
// We can't evaluate floating point casts or truncations.
1533+
if (CE1Op0->getType()->isFloatingPointTy())
1534+
break;
1535+
15321536
// If the cast is not actually changing bits, and the second operand is a
15331537
// null pointer, do the comparison with the pre-casted value.
15341538
if (V2->isNullValue() &&
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; RUN: opt -S -ipsccp < %s | FileCheck %s
2+
target datalayout = "E-m:e-i64:64-n32:64"
3+
target triple = "powerpc64-bgq-linux"
4+
5+
define void @test(i32 signext %n) {
6+
7+
; CHECK-LABEL: @test
8+
9+
entry:
10+
br i1 undef, label %if.then, label %if.end
11+
12+
if.then: ; preds = %entry
13+
ret void
14+
15+
if.end: ; preds = %entry
16+
br i1 undef, label %if.then2, label %if.end4
17+
18+
if.then2: ; preds = %if.end
19+
unreachable
20+
21+
if.end4: ; preds = %if.end
22+
%sub.n = select i1 undef, i32 undef, i32 %n
23+
switch i32 %sub.n, label %if.else14 [
24+
i32 0, label %if.then9
25+
i32 1, label %if.then12
26+
]
27+
28+
if.then9: ; preds = %if.end4
29+
unreachable
30+
31+
if.then12: ; preds = %if.end4
32+
unreachable
33+
34+
if.else14: ; preds = %if.end4
35+
br label %do.body
36+
37+
do.body: ; preds = %do.body, %if.else14
38+
%scale.0 = phi ppc_fp128 [ 0xM3FF00000000000000000000000000000, %if.else14 ], [ %scale.0, %do.body ]
39+
br i1 undef, label %do.body, label %if.then33
40+
41+
if.then33: ; preds = %do.body
42+
br i1 undef, label %_ZN5boost4math4signIgEEiRKT_.exit30, label %cond.false.i28
43+
44+
cond.false.i28: ; preds = %if.then33
45+
%0 = bitcast ppc_fp128 %scale.0 to i128
46+
%tobool.i26 = icmp slt i128 %0, 0
47+
br label %_ZN5boost4math4signIgEEiRKT_.exit30
48+
49+
_ZN5boost4math4signIgEEiRKT_.exit30: ; preds = %cond.false.i28, %if.then33
50+
unreachable
51+
}
52+

0 commit comments

Comments
 (0)