[InstCombine] Avoid passing pow attributes to sqrt

As described in issue #58475, we could pass the attributes of pow to sqrt and crash.

Differential Revision: https://reviews.llvm.org/D137454
This commit is contained in:
Miguel Saldivar
2022-11-07 11:26:30 -05:00
committed by Sanjay Patel
parent b62c81b836
commit de36d39e24
2 changed files with 16 additions and 2 deletions

View File

@@ -2164,8 +2164,8 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilderBase &B) {
return nullptr;
ExpoF = &ExpoI;
Sqrt = getSqrtCall(Base, Pow->getCalledFunction()->getAttributes(),
Pow->doesNotAccessMemory(), M, B, TLI);
Sqrt = getSqrtCall(Base, AttributeList(), Pow->doesNotAccessMemory(), M,
B, TLI);
if (!Sqrt)
return nullptr;
}

View File

@@ -0,0 +1,14 @@
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
; This is a check to assure the attributes of `pow` do
; not get passed to sqrt.
define void @pow_to_sqrt(double %x) {
; CHECK-LABEL: @pow_to_sqrt(
; CHECK-NEXT: [[SQRT:%.*]] = call afn double @sqrt(double [[X:%.*]])
; CHECK-NEXT: ret void
;
%call = call afn double @pow(double %x, double 1.5)
ret void
}
declare double @pow(double noundef, double noundef)