[llvm-dev] GVN-Hoist test case not working

Digvijay Gour via llvm-dev llvm-dev at lists.llvm.org
Sun Apr 7 11:17:12 PDT 2019


Hello,

I was trying a basic example on LLVM GVN Hoist and output differs from what
I expect. Am I missing something ?

*Code* :

int main()
{
int x = 7;
int a = 0;
if(a == 7){
x = 1;
a = 8 * x;
} else {
x = 1;
a = 2 * x;
}
return 0;
}

*Commands* :
clang-8 -O0 -S -emit-llvm test.c
opt-8 -gvn-hoist -S < test.ll

*Output :*

; ModuleID = '<stdin>'
source_filename = "test.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, i32* %1, align 4
  store i32 7, i32* %2, align 4
  store i32 0, i32* %3, align 4
  %4 = load i32, i32* %3, align 4
  %5 = icmp eq i32 %4, 7
  br i1 %5, label %6, label %9

; <label>:6:                                      ; preds = %0
  store i32 1, i32* %2, align 4
  %7 = load i32, i32* %2, align 4
  %8 = mul nsw i32 8, %7
  store i32 %8, i32* %3, align 4
  br label %12

; <label>:9:                                      ; preds = %0
  store i32 1, i32* %2, align 4
  %10 = load i32, i32* %2, align 4
  %11 = mul nsw i32 2, %10
  store i32 %11, i32* %3, align 4
  br label %12

; <label>:12:                                     ; preds = %9, %6
  ret i32 0
}

attributes #0 = { noinline nounwind optnone uwtable
"correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"min-legal-vector-width"="0" "no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "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" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 8.0.0-svn356034-1~exp1~20190313093039.54
(branches/release_80)"}

Thank you,
Digvijay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190407/5bc769cf/attachment.html>


More information about the llvm-dev mailing list