Issue 182452
Summary Automatically adds ZExt or trunc to BuildArrayMalloc
Labels new issue
Assignees
Reporter VertexTse
    I was writing code, and after I came across this problem, I wrote this test code:
```cs
var a = builder.BuildAlloca(ctx.Int32Type);
builder.BuildStore(CreateConstant(5), a);
_size = builder.BuildLoad2(ctx.Int32Type, a);
var _mem = builder.BuildArrayMalloc(LLType.Cast(@int.Type), _size);
```
and I get this IR code when compiling, why if the type is Int32 it adds ZExt, but if the size is set to Int64 it calls trunc?
```ll
  %7 = alloca i32, align 4
 store i32 5, ptr %7, align 4
  %8 = load i32, ptr %7, align 4
  %9 = zext i32 %8 to i32 ; Type too small for ZExt
  %mallocsize = mul i32 %9, ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i32)
  %10 = tail call ptr @malloc(i32 %mallocsize)
```
and when I compare two Int32 I get:
```ll
 %4 = load i32, ptr %3, align 4
  %5 = icmp eq i32 %4, i32 0 ; Both operands to ICmp instruction are not of the same type!
  br i1 %5, label %IC_4, label %IC_5
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to