[llvm-dev] Bug on llvm backend (llc) when the integer type is not power of 2?

Craig Topper via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 9 19:28:54 PST 2021


Per the LangRef for load. https://llvm.org/docs/LangRef.html#id208

 "When loading a value of a type like i20 with a size that is not an
integral number of bytes, the result is undefined if the value was not
originally written using a store of the same type."

~Craig


On Tue, Mar 9, 2021 at 7:22 PM Fangqing Du via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi all,
>
> When I run cmd '*llc -mtriple=x86_64-linux -filetype=obj tmp.ll -o tmp.o*'
> and '*g++ tmp.o -o exe*' on following llvm-ir, I'll get wrong output.
> Here '%r' and '%zt' should be 0x3FFFD, but output is 0xFFFFFD.
>
> Is this a bug?
> If it's a bug, then how can I workaround this? (Any llc option can avoid
> this?)
>
> Thanks a lot!
> Fangqing
> Xilinx Inc.
>
> ; ModuleID = 'main7.bc'
>
> source_filename = "main.cpp"
>
> target datalayout =
> "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
>
> target triple = "x86_64-unknown-linux-gnu"
>
>
> @.str = private unnamed_addr constant [9 x i8] c"adu: %d\0A\00", align 1
>
>
> ; Function Attrs: noinline norecurse optnone uwtable
>
> define i32 @main() #0 {
>
> entry:
>
>   %a = alloca i24, align 4
>
>   store i24 -3, i24* %a, align 4; 0xFFFFFD
>
>   %bc = bitcast i24* %a to i18*
>
>   %r = load i18, i18* %bc, align 4
>
>   %zt = zext i18 %r to i40; should be 0x3FFFD
>
>   ;%or = or i40 %zt, 267386880
>
>   %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8],
> [9 x i8]* @.str, i32 0, i32 0), i18 %r)
>
>   %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8],
> [9 x i8]* @.str, i32 0, i32 0), i40 %zt)
>
>   ;%call3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x
> i8], [9 x i8]* @.str, i32 0, i32 0), i40 %or)
>
>   ret i32 0
>
> }
>
>
> declare i32 @printf(i8*, ...) #1
>
>
> attributes #0 = { noinline norecurse optnone uwtable
> "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"=
> "false" "frame-pointer"="all" "less-precise-fpmad"="false"
> "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"=
> "false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
> "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"=
> "+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"=
> "false" }
>
> attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false"
> "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"=
> "false" "no-infs-fp-math"="false" "no-nans-fp-math"="false"
> "no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
> "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"=
> "+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"=
> "false" }
>
>
> !llvm.module.flags = !{!0}
>
> !llvm.ident = !{!1}
>
>
> !0 = !{i32 1, !"wchar_size", i32 4}
>
> !1 = !{!"clang version 7.0.0 "}
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210309/d9e38bfd/attachment-0001.html>


More information about the llvm-dev mailing list