Skip to content

Commit c453098

Browse files
authored
Fix trunc i1 (rust-lang#822)
1 parent d345907 commit c453098

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,16 +1687,19 @@ void TypeAnalyzer::visitTruncInst(TruncInst &I) {
16871687
size_t inSize = (DL.getTypeSizeInBits(I.getOperand(0)->getType()) + 7) / 8;
16881688
size_t outSize = (DL.getTypeSizeInBits(I.getType()) + 7) / 8;
16891689
if (direction & DOWN)
1690-
updateAnalysis(&I,
1691-
getAnalysis(I.getOperand(0))
1692-
.ShiftIndices(DL, /*off*/ 0, inSize, /*addOffset*/ 0)
1693-
.ShiftIndices(DL, /*off*/ 0, outSize, /*addOffset*/ 0),
1694-
&I);
1690+
if (outSize != 1)
1691+
updateAnalysis(&I,
1692+
getAnalysis(I.getOperand(0))
1693+
.ShiftIndices(DL, /*off*/ 0, inSize, /*addOffset*/ 0)
1694+
.ShiftIndices(DL, /*off*/ 0, outSize, /*addOffset*/ 0),
1695+
&I);
1696+
// Don't propagate up a trunc float -> i8
16951697
if (direction & UP)
1696-
updateAnalysis(
1697-
I.getOperand(0),
1698-
getAnalysis(&I).ShiftIndices(DL, /*off*/ 0, outSize, /*addOffset*/ 0),
1699-
&I);
1698+
if (outSize != 1 || inSize == 1)
1699+
updateAnalysis(
1700+
I.getOperand(0),
1701+
getAnalysis(&I).ShiftIndices(DL, /*off*/ 0, outSize, /*addOffset*/ 0),
1702+
&I);
17001703
}
17011704

17021705
void TypeAnalyzer::visitZExtInst(ZExtInst &I) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: %opt < %s %loadEnzyme -print-type-analysis -type-analysis-func=d -o /dev/null | FileCheck %s
2+
3+
define i8 @d(double %x) {
4+
entry:
5+
%bc = bitcast double %x to i64
6+
%t = trunc i64 %bc to i8
7+
ret i8 %t
8+
}
9+
10+
; CHECK: d - {[-1]:Integer} |{[-1]:Float@double}:{}
11+
; CHECK-NEXT: double %x: {[-1]:Float@double}
12+
; CHECK-NEXT: entry
13+
; CHECK-NEXT: %bc = bitcast double %x to i64: {[-1]:Float@double}
14+
; CHECK-NEXT: %t = trunc i64 %bc to i8: {[-1]:Integer}
15+
; CHECK-NEXT: ret i8 %t: {}

0 commit comments

Comments
 (0)