snu-sf-class / swpp202401

Principles and Practices of Software Development Main Repository
14 stars 4 forks source link

[Project] Vector operation error #90

Open Wits15730 opened 6 months ago

Wits15730 commented 6 months ago

The code mentioned at #88 seems to be producing an error, after applying the change in #89 I changed the reduction instruction to add instructions.

-Error Message: swpp-compiler: /root/llvm-project/llvm/lib/IR/Instructions.cpp:3335: static CastInst llvm::CastInst::Create(Instruction::CastOps, Value , Type , const Twine &, Instruction ): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed. Aborted (core dumped)

-Reproducing Example:

define dso_local i64 @matmul(i32 noundef %dim, i64 %y, ptr nocapture noundef writeonly %c, ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) local_unnamed_addr {
entry:
  br label %vector.body

restart:                                          ; preds = %vector.body
  br label %vector.body

vector.body:                                      ; preds = %restart, %entry
  %offset.idx = phi i64 [ 0, %entry ], [ %z, %restart ]
  %vec.phi = call <4 x i64> @vbcast_i64x4(i64 1)
  %0 = trunc i64 %offset.idx to i32
  %1 = add i32 %0, 4
  %2 = zext i32 %1 to i64
  %3 = getelementptr inbounds i64, ptr %a, i64 %2
  %4 = getelementptr inbounds i64, ptr %3, i32 0
  %wide.load = load <4 x i64>, ptr %4, align 8
  %5 = add i32 %1, %1
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds i64, ptr %b, i64 %6
  %8 = getelementptr inbounds i64, ptr %7, i32 0
  %wide.load11 = load <4 x i64>, ptr %8, align 8
  %9 = mul <4 x i64> %wide.load11, %wide.load
  %10 = add <4 x i64> %9, %vec.phi
  %z = add nuw i64 %offset.idx, 4
  %11 = icmp eq i64 %z, %y
  br i1 %11, label %for.end22, label %restart

for.end22:                                        ; preds = %vector.body
  %elem_1 = extractelement <4 x i64> %10, i32 0
  %elem_2 = extractelement <4 x i64> %10, i32 1
  %elem_3 = extractelement <4 x i64> %10, i32 2
  %elem_4 = extractelement <4 x i64> %10, i32 3
  %add_12 = add i64 %elem_1, %elem_2
  %add_34 = add i64 %elem_3, %elem_4
  %add_final = add i64 %add_12, %add_34
  ret i64 %add_final
}

declare <4 x i64> @vbcast_i64x4(i64)
strikef commented 6 months ago

This issue has been discussed in-person; it is possibly a duplicate of #88 and has been fixed in #89