[llvm-dev] Is the instruction %4 = select i1 %tobool.i, metadata !12, metadata !10 legal?

Lin, Jin via llvm-dev llvm-dev at lists.llvm.org
Fri Dec 2 15:01:10 PST 2016


Many thanks for pointing out this.  We will see whether the problem will go away once the pull down from the community version is completed.

From: David Majnemer [mailto:david.majnemer at gmail.com]
Sent: Friday, December 2, 2016 2:04 PM
To: Lin, Jin <jin.lin at intel.com>
Cc: Caldarale, Charles R <Chuck.Caldarale at unisys.com>; llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] Is the instruction %4 = select i1 %tobool.i, metadata !12, metadata !10 legal?

I cannot reproduce this in LLVM r288194. Your IR seems to be quite non-typical with intrinsics like "@llvm..fakeload.p0p0i32"...
I'm not sure what you have here but it can be explained if you have branched off of some older LLVM.  Hal fixed a bug that looked just like this one in r280866: https://github.com/llvm-mirror/llvm/commit/9e7800b23b43fa5f2ada1be28e71fb81f3f38437

On Fri, Dec 2, 2016 at 11:08 AM, Lin, Jin via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
To reproduce the issue, please use the command line "opt -simplifycfg filename".

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.G = type { %struct.ordered_index_node*, i32 }
%struct.ordered_index_node = type { %struct.B, %struct.F }
%struct.B = type { i32 }
%struct.F = type { i32*, i32* }

$_ZN1G13final_insert_Ev = comdat any

$_ZN1G7insert_Ev = comdat any

$_ZN1F4leftEv = comdat any

$_ZN1F5rightEv = comdat any

; Function Attrs: uwtable
define void @_Z3fn1v() local_unnamed_addr #0 {
entry:
  %t = alloca %struct.G, align 8
  %0 = bitcast %struct.G* %t to i8*
  call void @llvm.lifetime.start(i64 16, i8* %0) #5
  call void @_ZN1G13final_insert_Ev(%struct.G* nonnull %t)
  call void @llvm.lifetime.end(i64 16, i8* %0) #5
  ret void
}

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #1

; Function Attrs: uwtable
define linkonce_odr void @_ZN1G13final_insert_Ev(%struct.G* %this) local_unnamed_addr #0 comdat align 2 {
entry:
  %call = call dereferenceable(16) %struct.G* @_ZN1G5finalEv(%struct.G* %this)
  %link_point_c.i = getelementptr inbounds %struct.G, %struct.G* %call, i64 0, i32 1
  %0 = load i32, i32* %link_point_c.i, align 8, !tbaa !1
  %tobool.i = icmp eq i32 %0, 0
  %1 = bitcast %struct.G* %call to i8**
  %2 = load i8*, i8** %1, align 8, !tbaa !7
  br i1 %tobool.i, label %cond.false.i, label %cond.true.i

cond.true.i:                                      ; preds = %entry
  %add.ptr.i = getelementptr inbounds i8, i8* %2, i64 8
  %left_.i.i = bitcast i8* %add.ptr.i to i32**
  %3 = call i32** @llvm..fakeload.p0p0i32(i32** %left_.i.i, metadata !8) #5
  br label %_ZN1G7insert_Ev.exit

cond.false.i:                                     ; preds = %entry
  %right_.i.i = getelementptr inbounds i8, i8* %2, i64 16
  %4 = bitcast i8* %right_.i.i to i32**
  %5 = call i32** @llvm..fakeload.p0p0i32(i32** %4, metadata !11) #5
  br label %_ZN1G7insert_Ev.exit

_ZN1G7insert_Ev.exit:                             ; preds = %cond.true.i, %cond.false.i
  %call4.sink.i = phi i32** [ %5, %cond.false.i ], [ %3, %cond.true.i ]
  %6 = load i32*, i32** %call4.sink.i, align 8, !tbaa !12
  call void @_ZN18ordered_index_node9from_implEPi(i32* %6)
  ret void
}

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #1

declare dereferenceable(16) %struct.G* @_ZN1G5finalEv(%struct.G*) local_unnamed_addr #2

; Function Attrs: uwtable
define linkonce_odr void @_ZN1G7insert_Ev(%struct.G* %this) local_unnamed_addr #0 comdat align 2 {
entry:
  %link_point_c = getelementptr inbounds %struct.G, %struct.G* %this, i64 0, i32 1
  %0 = load i32, i32* %link_point_c, align 8, !tbaa !1
  %tobool = icmp eq i32 %0, 0
  %1 = bitcast %struct.G* %this to i8**
  %2 = load i8*, i8** %1, align 8, !tbaa !7
  br i1 %tobool, label %cond.false, label %cond.true

cond.true:                                        ; preds = %entry
  %add.ptr = getelementptr inbounds i8, i8* %2, i64 8
  %left_.i = bitcast i8* %add.ptr to i32**
  %3 = call i32** @llvm..fakeload.p0p0i32(i32** %left_.i, metadata !8) #5
  br label %cond.end

cond.false:                                       ; preds = %entry
  %right_.i = getelementptr inbounds i8, i8* %2, i64 16
  %4 = bitcast i8* %right_.i to i32**
  %5 = call i32** @llvm..fakeload.p0p0i32(i32** %4, metadata !11) #5
  br label %cond.end

cond.end:                                         ; preds = %cond.false, %cond.true
  %call4.sink = phi i32** [ %5, %cond.false ], [ %3, %cond.true ]
  %6 = load i32*, i32** %call4.sink, align 8, !tbaa !12
  call void @_ZN18ordered_index_node9from_implEPi(i32* %6)
  ret void
}

declare void @_ZN18ordered_index_node9from_implEPi(i32*) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define linkonce_odr dereferenceable(8) i32** @_ZN1F4leftEv(%struct.F* %this) local_unnamed_addr #3 comdat align 2 {
entry:
  %left_ = getelementptr inbounds %struct.F, %struct.F* %this, i64 0, i32 0
  %0 = call i32** @llvm..fakeload.p0p0i32(i32** %left_, metadata !8) #5
  ret i32** %0
}

; Function Attrs: nounwind uwtable
define linkonce_odr dereferenceable(8) i32** @_ZN1F5rightEv(%struct.F* %this) local_unnamed_addr #3 comdat align 2 {
entry:
  %right_ = getelementptr inbounds %struct.F, %struct.F* %this, i64 0, i32 1
  %0 = call i32** @llvm..fakeload.p0p0i32(i32** %right_, metadata !11) #5
  ret i32** %0
}

; Function Attrs: nounwind readnone
declare i32** @llvm..fakeload.p0p0i32(i32**, metadata) #4

attributes #0 = { uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-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 = { argmemonly nounwind }
attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-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 #3 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-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 #4 = { nounwind readnone }
attributes #5 = { nounwind }

!llvm.ident = !{!0}

!0 = !{!"clang version 4.0.0 (branches/20501)"}
!1 = !{!2, !6, i64 8}
!2 = !{!"struct at _ZTS1G", !3, i64 0, !6, i64 8}
!3 = !{!"pointer at _ZTSP18ordered_index_node", !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C++ TBAA"}
!6 = !{!"int", !4, i64 0}
!7 = !{!2, !3, i64 0}
!8 = !{!9, !10, i64 0}
!9 = !{!"struct at _ZTS1F", !10, i64 0, !10, i64 8}
!10 = !{!"pointer at _ZTSPi", !4, i64 0}
!11 = !{!9, !10, i64 8}
!12 = !{!10, !10, i64 0}
-----Original Message-----
From: Caldarale, Charles R [mailto:Chuck.Caldarale at unisys.com<mailto:Chuck.Caldarale at unisys.com>]
Sent: Friday, December 2, 2016 10:51 AM
To: Lin, Jin <jin.lin at intel.com<mailto:jin.lin at intel.com>>; llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
Subject: RE: Is the instruction %4 = select i1 %tobool.i, metadata !12, metadata !10 legal?

> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>]
> On Behalf Of Lin, Jin via llvm-dev
> Subject: [llvm-dev] Is the instruction %4 = select i1 %tobool.i, metadata !12, metadata !10 legal?

> I wonder whether this is valid LLVM IR:
>       %4 = select i1 %tobool.i, metadata !12, metadata !10

> Before CFGSimplify
> cond.true.i:                                      ; preds = %entry
>  %add.ptr.i = getelementptr inbounds i8, i8* %2, i64 8
>  %left_.i.i = bitcast i8* %add.ptr.i to i32**
>  %3 = call i32** @llvm.fakeload.p0p0i32(i32** %left_.i.i, metadata !8) #6  br label %_ZN1G7insert_Ev.exit
> cond.false.i:                                     ; preds = %entry
>  %right_.i.i = getelementptr inbounds i8, i8* %2, i64 16
>  %4 = bitcast i8* %right_.i.i to i32**
>  %5 = call i32** @llvm.fakeload.p0p0i32(i32** %4, metadata !11) #6
>  br label %_ZN1G7insert_Ev.exit

> After CFGSimplify
>  %4 = select i1 %tobool.i, metadata !12, metadata !10
>  %add.ptr.i = getelementptr inbounds i8, i8* %2, i64 %3
>  %left_.i.i = bitcast i8* %add.ptr.i to i32**
>  %5 = call i32** @llvm.fakeload.p0p0i32(i32** %left_.i.i, metadata %4) #6
>  %6 = load i32*, i32** %5, align 8, !tbaa !8

Is there any more to the original IR? I don't think CFGSimplify would have magically created %tobool.i, yet it doesn't appear in the provided before snippet.

 - Chuck

_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
http://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/20161202/2391a580/attachment.html>


More information about the llvm-dev mailing list